Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/web/api/atob/index.md
6532 views
---
title: atob() slug: Web/API/atob page-type: web-api-global-function browser-compat: api.atob
---

{{APIRef("HTML DOM")}}

The atob() function decodes a string of data which has been encoded using {{glossary("Base64")}} encoding. You can use the {{domxref("btoa","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.

For use with Unicode or UTF-8 strings, see the note on "Unicode strings" in the page for {{domxref("btoa", "btoa()")}}.

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

  • InvalidCharacterError {{domxref("DOMException")}}

    • : Thrown if encodedData is not valid base64.

Examples

const encodedData = btoa("Hello, world"); // encode a string const decodedData = atob(encodedData); // decode the string

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also