web api instance method
WorkerGlobalScope: atob() method
Available in workers
The atob() method of the WorkerGlobalScope interface decodes a
string of data which has been encoded using Base64 encoding. You can use
the btoa() method to encode and transmit
data which may otherwise cause communication problems, then transmit it and use the
atob() method to decode the data again. For example, you can encode,
transmit, and decode control characters such as ASCII values 0 through 31.
Syntax
atob(encodedData)
Parameters
encodedData- : A binary string (i.e., a string in which each character in the string is treated as a byte of binary data) containing base64-encoded data.
Return value
An ASCII string containing decoded data from encodedData.
Exceptions
InvalidCharacterErrorDOMException- : Thrown if
encodedDatais not valid base64.
- : Thrown if
Examples
const encodedData = self.btoa("Hello, world"); // encode a string
const decodedData = self.atob(encodedData); // decode the string
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- A polyfill of
atobis available incore-js dataURLsatob(): the same method, but in window scopes.btoa()fromBase64()