Why the names btoa and atob for Base64 encoder decoder functions?
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
toZ
,a
toz
,0
to9
,+
,/
, 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:
Old Unix names, hard to find man pages rn but see https://t.co/lWkceMwFad. 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).— BrendanEich (@BrendanEich) May 21, 2018
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.