Encoding And Decoding Strings With Base64 Using JavaScript
btoa() and atob() are two Base64 JavaScript functions that are a core part of the HTML specification and available in all modern browsers.
btoa() JavaScript Function
Type this code in browser’s web developer console log:
// Define the string
var decodedStringBtoA = 'Hello World!';
// Encode the String
var encodedStringBtoA = btoa(decodedStringBtoA);
console.log(encodedStringBtoA);
Output:
SGVsbG8gV29ybGQh
atob() JavaScript Function
Type this code in browser’s web developer console log:
// Define the string
var encodedStringAtoB = 'SGVsbG8gV29ybGQh';
// Decode the String
var decodedStringAtoB = atob(encodedStringAtoB);
console.log(decodedStringAtoB);
Output:
Hello World!
Bibliography:
Eloquent JavaScript;Marijn Haverbeke;No Starch Press
Effective JavaScript;David Herman;Addison Wesley
JavaScript: The Definitive Guide;David Flanagan;O'Reilly
https://www.instagram.com/thecodecrumbs/
Tidak ada komentar:
Posting Komentar