Why are they named btoa() and atob()?#

If you have ever needed to encode text to Base64 or decode a Base64 encoded string to plain text, you should be familiar with the methods btoa() and atob().

Their names might have caught your attention and got you wondering, "Are these random names along the lines of x_to_y and y_to_x? Why are they named so?"

Here is the explanation:

  • btoa implies "binary to ASCII"
  • atob implies "ASCII to binary"

Here "binary" and "ASCII" are used in a slightly different context.

  • ASCII - printable ASCII characters, A to Z, a to z, 0 to 9, +, /, and =, which form the Base64 character set
  • Binary - Any printable or non-printable characters

Brendan Eich, the creator of JavaScript explains his decision in this tweet:

This article is posted under /webdev/javascript and not /javascript because btoa() and atob() are not part of the core JavaScript specification; they are browser APIs, and that's the reason why there's no btoa() and atob() in Node.js.

References#

  1. https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
  2. https://html.spec.whatwg.org/multipage/webappapis.html#atob
  3. https://en.wikipedia.org/wiki/Base64