Let's see how you can encode a string by using the btoa() function:
Also, check our Base64 Encoder tool.
The default btoa() function works well for binary data consisted of 8-bit bytes(UTF-8).
However, the btoa() function accepts a string where each character represents an 8-bit byte. If a string contains characters that can't be represented in 8 bits(e.g. UTF16), it will break.
To handle Unicode characters, you need, firstly, to escape the string to an array of 8-bit bytes and then use the window.btoa() function to encode to Base64:
There is a counterpart function atob() to convert from base64 encoding to string. The atob() function returns a string where each character represents an 8-bit byte, meaning its value will be between 0 and 0xff.
Check out Base 64 Decoder tool.
Base64 encoding and decoding