🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › btoa
Window: btoa() method - Web APIs - MDN Web Docs - Mozilla
An ASCII string containing the Base64 representation of stringToEncode. ... The string contained a character that did not fit in a single byte. See "Unicode strings" below for more detail. ... const encodedData = window.btoa("Hello, world"); // encode a string const decodedData = ...
🌐
Medium
medium.com › @lvhaitao0301 › introduction-of-javascripts-btoa-function-223f6e82a359
Introduction of JavaScript’s btoa function | by HAITAO LYU | Medium
February 13, 2025 - function utf8ToBase64(str) { const bytes = new TextEncoder().encode(str); let binary = ''; for (const byte of bytes) { binary += String.fromCharCode(byte); } return btoa(binary); } const base64 = utf8ToBase64('你好'); console.log(base64); // Outputs "5L2g5aW9"
🌐
W3Schools
w3schools.com › jsref › met_win_btoa.asp
Window btoa() Method
The btoa() method uses the "A-Z", "a-z", "0-9", "+", "/" and "=" characters to encode the string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › WorkerGlobalScope › btoa
WorkerGlobalScope: btoa() method - Web APIs | MDN
const encodedData = self.btoa("Hello, world"); // encode a string const decodedData = self.atob(encodedData); // decode the string · Base64, by design, expects binary data as its input. In terms of JavaScript strings, this means strings in which the code point of each character occupies only ...
🌐
LinkedIn
linkedin.com › pulse › exploring-base64-encoding-decoding-functions-btoa-atob-falamarzi
Exploring the Base64 Encoding and Decoding Functions in JavaScript: btoa() and atob()
July 13, 2023 - const encodedData = btoa("Hello, world"); // 'SGVsbG8sIHdvcmxk' const decodedData = atob(encodedData); // "Hello, world"
🌐
Base64.Guru
base64.guru › home › developers › javascript
JavaScript Base64 Encode | JavaScript | Developers | Base64
// Before encoding data to Base64 the btoa() function converts it to String() // It is for this reason that you will not get any errors if you pass a “wrong” data type // For example, that is why in the examples below you will get the same results btoa(null); //-> "bnVsbA==" btoa('null'); //-> "bnVsbA==" btoa({}); //-> "W29iamVjdCBPYmplY3Rd" btoa('[object Object]'); //-> "W29iamVjdCBPYmplY3Rd" btoa([0,1]); //-> "MCwx" btoa('0,1'); //-> "MCwx" btoa(function(){}); //-> "ZnVuY3Rpb24oKXt9" btoa('function(){}'); //-> "ZnVuY3Rpb24oKXt9"
🌐
Educative
educative.io › answers › what-is-the-use-of-the-windowbtoa-method-in-javascript
What is the use of the window.btoa() method in JavaScript?
Line 14: We use the input variable and give it as a parameter to window.btoa() method. The return value we get is assigned to the variable base64. So now, base64 contains our encoded string. Line 15: Here, we use Javascript's alert() method to display the encoded string to the reader.
🌐
Base64
base64.sh › blog › javascript-atob-btoa
JavaScript atob() and btoa() Functions: Quick Reference
function safeBase64Decode(str) { try { return atob(str); } catch (e) { console.error('Invalid Base64:', e); return null; } } function safeBase64Encode(str) { try { return btoa(str); } catch (e) { // Likely Unicode issue return btoa(unescape(encodeURIComponent(str))); } }
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-use-the-btoa-and-atob-global-functions-in-javascript-adb5497d7ce3
How to Use the btoa And atob Global Functions in JavaScript | by Chris1993 | JavaScript in Plain English
April 25, 2024 - This encoding is often used to ... to encode a string into Base64. For example, the following code encodes the string "Hello, world!" into Base64:...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › html › html-dom-window-btoa-method
HTML | DOM Window btoa() Method - GeeksforGeeks
August 5, 2022 - <!DOCTYPE html> <html> <head> <title> Window btoa() Method in HTML </title> <style> h1 { color: green; } h2 { font-family: Impact; } body { text-align: center; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>Window btoa() Method</h2> <p> For encoding a string in base-64 format, double click the "Encode Message" button: </p> <button ondblclick="encode()"> Encode Message </button> <p id="myEncoding"></p> <script> function encode() { var original = "GeeksforGeeks"; var encoded = window.btoa(original); var output = "Encoded String : " + encoded; document.getElementById("myEncoding").innerHTML = "Original String: " + original + "<br>" + output; } </script> </body> </html>
🌐
Webdevtutor
webdevtutor.net › blog › javascript-btoa
Understanding the JavaScript btoa() Method
Let's look at a more practical example where we encode user credentials before sending them to a server: javascript const username = 'john_doe'; const password = 'secretpassword123'; const credentials = ${username}:${password}; const encodedCredentials = btoa(credentials); console.log(encodedCredentials); // Output: "am9obi1kb2U6c2VjcmV0cGFzc3dvcmQxMjM="
🌐
Base64 Encode
base64encode.net › javascript-btoa
JavaScript btoa - Base64 Encode
btoa('use javascript btoa to encode data in base64 format') dXNlIGphdmFzY3JpcHQgYnRvYSB0byBlbmNvZGUgZGF0YSBpbiBiYXNlNjQgZm9ybWF0 · JavaScript atob · Image to Base64 · File to Base64 · PDF to Base64 · Base32 Encode ·
🌐
Dottoro
help.dottoro.com › ljvfsbvr.php
btoa method (window) JavaScript
Use the atob method to decode a base-64 encoded string. The btoa method uses the A-Z, a-z, 0-9, +, / and = characters for encoding a string. ... You can find the related objects in the Supported by objects section below.
🌐
W3Schools
w3schools.com › jsref › met_win_atob.asp
Window atob() Method
The atob() method decodes a string that has been encoded by the btoa() method.
🌐
Medium
medium.com › @tuteja_lovish › exploring-atob-and-btoa-in-javascript-a-guide-to-base64-encoding-and-decoding-ffd98197c42d
Exploring atob and btoa in JavaScript: A Guide to Base64 Encoding and Decoding | by CodeTalks | Medium
December 4, 2024 - btoa: Converts binary data to a Base64-encoded string. atob: Decodes a Base64-encoded string back into binary data. These functions are native to JavaScript and are part of the Window object in browsers.
🌐
npm
npmjs.com › package › btoa
btoa - npm
March 28, 2018 - Uses Buffer to emulate the exact functionality of the browser's btoa (except that it supports some unicode that the browser may not).
      » npm install btoa
    
Published: Mar 28, 2018
Version: 1.2.1
🌐
Medium
medium.com › @humbleCoder007 › btoa-and-atob-encoding-and-decoding-2aaea4080522
BTOA AND ATOB encoding and decoding | by The Humble Coder | Medium
May 18, 2023 - var originalUrl = 'https://www.example.com/page?param=value'; var encodedUrl = btoa(originalUrl); console.log(encodedUrl);
🌐
Medium
i-m-prabhat.medium.com › understanding-the-btoa-method-in-javascript-a-comprehensive-guide-84f5e4f8b62e
Understanding the `btoa` Method in JavaScript: A Comprehensive Guide | by Prabhat Patel | Medium
June 2, 2024 - Base64 encoding represents binary data using 64 different ASCII characters, including uppercase and lowercase letters, numbers, and a few special symbols. The btoa method converts each byte of binary data into a group of four ASCII characters, making it safe to include in URLs, HTTP headers, and other text-based formats.
Top answer
1 of 5
296

I asked Brendan Eich (the creator of JavaScript) if he picked those names on Twitter and he responded:

Old Unix names, hard to find man pages rn but see https://www.unix.com/man-page/minix/1/btoa/ …. The names carried over from Unix into the Netscape codebase. I reflected them into JS in a big hurry in 1995 (after the ten days in May but soon).

In case the Minix link breaks, here's the man page content:

BTOA(1)                                           BTOA(1)

NAME
       btoa - binary to ascii conversion

SYNOPSIS
       btoa [-adhor] [infile] [outfile]

OPTIONS
       -a     Decode, rather than encode, the file

       -d     Extracts repair file from diagnosis file

       -h     Help menu is displayed giving the options

       -o     The obsolete algorithm is used for backward compatibility

       -r     Repair a damaged file

EXAMPLES
       btoa <a.out >a.btoa # Convert a.out to ASCII

       btoa -a <a.btoa >a.out
               # Reverse the above

DESCRIPTION
       Btoa  is  a  filter that converts a binary file to ascii for transmission over a telephone
       line.  If two file names are provided, the first in used for input and the second for out-
       put.   If  only one is provided, it is used as the input file.  The program is a function-
       ally similar alternative to uue/uud, but the encoding is completely different.  Since both
       of  these are widely used, both have been provided with MINIX.  The file is expanded about
       25 percent in the process.

SEE ALSO
       uue(1), uud(1).
2 of 5
217

The atob() and btoa() methods allow authors to transform content to and from the base64 encoding.

In these APIs, for mnemonic purposes, the "b" can be considered to stand for "binary", and the "a" for "ASCII". In practice, though, for primarily historical reasons, both the input and output of these functions are Unicode strings.

From : http://www.w3.org/TR/html/webappapis.html#atob