Skip to content

Instantly share code, notes, and snippets.

@sharnie
Created May 26, 2014 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharnie/a11ae1264c8af4d714e4 to your computer and use it in GitHub Desktop.
Save sharnie/a11ae1264c8af4d714e4 to your computer and use it in GitHub Desktop.
Javascript encode and decode string with base64
// Define the string
var string = 'Hello World!';
// Encode the String
var encodedString = btoa(string);
console.log(encodedString); // Outputs: "SGVsbG8gV29ybGQh"
// Decode the String
var decodedString = atob(encodedString);
console.log(decodedString); // Outputs: "Hello World!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment