atob
Decodes a Base64 string.
Available since: Web API
Syntax
atob(base64)Parameters
| Parameter | Type | Description |
|---|---|---|
| base64 | string | A Base64-encoded string. |
Return value
stringThe decoded string (each character is one byte).
Examples
The reverse conversion:
console.log(atob('SGVsbG8='));Output:
HelloDecoding UTF-8 text:
const binary = atob('0J/RgNC40LLQtdGC');
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
console.log(new TextDecoder().decode(bytes));Output:
ПриветNotes
The name means ASCII to binary. If the string is not valid Base64 it throws an InvalidCharacterError.
See also
- btoa — Encodes a string to Base64.
Related recipes
In the tutorial
- String methods — Useful string methods in JavaScript: finding a position, reading characters, padStart, repeat, split and join, method chains.