btoa()
The btoa()
method creates a
Base64-encoded ASCII string from a binary string (i.e., a
string in which each character in the string is treated as a byte
of binary data).
You can use this method to encode data which may otherwise cause communication
problems, transmit it, then use the atob()
method to decode the data again. For example, you can encode control
characters such as ASCII values 0 through 31.
Syntax
btoa(stringToEncode)
Parameters
stringToEncode
- : The binary string to encode.
Return value
An ASCII string containing the Base64 representation of
stringToEncode
.
Exceptions
InvalidCharacterError
- : The string contained a character that did not fit in a single byte. See "Unicode strings" below for more detail.