When I try to run the JS script below get an exception in the code:
var encode = window.btoa('Hiroto √')
"@lehesamudi.js:14:26
b.render/<@https://static.jsbin.com/js/prod/runner-4.1.8.min.js:1:13924
a.use/<@https://static.jsbin.com/js/prod/runner-4.1.8.min.js:1:10866
"
>Solution :
Try to escape before, please find the code below.
function encode(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}
function decode(str) {
return decodeURIComponent(escape(window.atob(str)));
}
// Usage:
encode('Encode me with UTF-8 char: ∑ßåœ ≈ ∆c') // "RW5jb2RlIG1lIHdpdGggVVRGLTggY2hhcjog4oiRw5/DpcWTIOKJiCDiiIZj"
decode("RW5jb2RlIG1lIHdpdGggVVRGLTggY2hhcjog4oiRw5/DpcWTIOKJiCDiiIZj") //'Encode me with UTF-8 char: ∑ßåœ ≈ ∆c'