Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Encode and Decode string in Javascript
// Decode a base-64 encoded string:
var quote = "Stay hungry. Stay foolish.";
var encode = window.btoa(quote);
var decode = window.atob(encode);
console.log("Encoded String: " + enc + "<br>" + "Decoded String: " + dec);
// The result will be:
// Encoded String: U3RheSBodW5ncnkuIFN0YXkgZm9vbGlzaC4=
// Decoded String: Stay hungry. Stay foolish.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment