Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

atob

Decodes a Base64 string.

Available since: Web API

Syntax

atob(base64)

Parameters

ParameterTypeDescription
base64stringA Base64-encoded string.

Return value

stringThe decoded string (each character is one byte).

Examples

The reverse conversion:

console.log(atob('SGVsbG8='));

Output:

Hello

Decoding 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.

Thanks for reading!

Donate to the site — we work hard for you.