Syntax
js
atob(encodedData)
Parameters
encodedData-
A base64-encoded string, using the alphabet produced by
Window.btoa().
Return value
A binary string containing raw bytes decoded from encodedData. Strings in JavaScript are encoded as UTF-16, so this means each character must have a code point less than 256, representing one byte of data.
Exceptions
InvalidCharacterErrorDOMException-
Thrown if
encodedDatais not valid base64.
Examples
js
const encodedData = window.btoa("Hello, world"); // encode a string
const decodedData = window.atob(encodedData); // decode the string
For more examples, see the Window.btoa() method.
Specifications
| Specification |
|---|
| HTML # dom-atob-dev |
Browser compatibility
See also
- A polyfill of
atobis available incore-js dataURLsWorkerGlobalScope.atob(): the same method, but in worker scopes.Window.btoa()Uint8Array.fromBase64()