---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# 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

```js
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.
