{"id":15055,"date":"2025-12-20T14:09:05","date_gmt":"2025-12-20T08:39:05","guid":{"rendered":"https:\/\/utho.com\/blog\/?p=15055"},"modified":"2025-12-23T14:35:47","modified_gmt":"2025-12-23T09:05:47","slug":"encoding-decoding-base64-javascript","status":"publish","type":"post","link":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/","title":{"rendered":"Encoding and Decoding Base64 Strings in JavaScript Explained"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Base64 is one of those things every developer <\/span><i><span style=\"font-weight: 400;\">uses<\/span><\/i><span style=\"font-weight: 400;\">, but very few truly <\/span><i><span style=\"font-weight: 400;\">understand<\/span><\/i><span style=\"font-weight: 400;\">. You see Base64 strings everywhere &#8211; inside JWT tokens, API payloads, cookies, image previews, and even those long \u201csecret-looking\u201d strings you often copy\u2013paste during integrations. It has become a universal way to safely transmit data across systems that were originally designed to handle only text.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15059 size-full\" src=\"https:\/\/utho.com\/blog\/wp-content\/uploads\/Base64-explain-in-30-seconds.png\" alt=\"Base64 explain in 30 seconds\" width=\"1536\" height=\"1024\" srcset=\"https:\/\/utho.com\/blog\/wp-content\/uploads\/Base64-explain-in-30-seconds.png 1536w, https:\/\/utho.com\/blog\/wp-content\/uploads\/Base64-explain-in-30-seconds-300x200.png 300w, https:\/\/utho.com\/blog\/wp-content\/uploads\/Base64-explain-in-30-seconds-1024x683.png 1024w, https:\/\/utho.com\/blog\/wp-content\/uploads\/Base64-explain-in-30-seconds-768x512.png 768w, https:\/\/utho.com\/blog\/wp-content\/uploads\/Base64-explain-in-30-seconds-150x100.png 150w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">But what exactly is Base64?<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Why does it turn a normal string into a long, unreadable sequence of characters?<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-weight: 400;\">And how does JavaScript encode and decode it behind the scenes?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When you understand Base64 deeply, you also understand how browsers, servers, and APIs protect data from corruption during transport. Base64 isn\u2019t encryption &#8211; it\u2019s simply a smart way of representing binary data in a text-friendly format. And because JavaScript works heavily with text and binary buffers, knowing how Base64 works gives you better control over authentication, file uploads, security tokens, and data processing.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this guide, we\u2019ll break Base64 down in the simplest possible way:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">What Base64 actually does<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">How encoding and decoding work internally<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Why web developers need it<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">And the exact JavaScript methods to use &#8211; from <\/span><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">atob()<\/span><span style=\"font-weight: 400;\"> to modern <\/span><span style=\"font-weight: 400;\">Buffer<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">TextEncoder<\/span><span style=\"font-weight: 400;\"> APIs<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">By the end, you won\u2019t just \u201cuse\u201d Base64 &#8211; you\u2019ll understand it like a pro.<\/span><\/p>\n<h2><b>1. What Is Base64 Encoding and Decoding?<\/b><\/h2>\n<h3><b>1. Base64 in Simple Words<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Base64 is a <\/span><b>binary-to-text encoding scheme<\/b><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> That means:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Input: Any binary data (string, image, file, etc.)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Output: A string made of only 64 characters + <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> for padding<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><b>Those 64 characters are:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Uppercase letters: <\/span><span style=\"font-weight: 400;\">A\u2013Z<\/span><span style=\"font-weight: 400;\"> (26)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Lowercase letters: <\/span><span style=\"font-weight: 400;\">a\u2013z<\/span><span style=\"font-weight: 400;\"> (26)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Digits: <\/span><span style=\"font-weight: 400;\">0\u20139<\/span><span style=\"font-weight: 400;\"> (10)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Symbols: <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\"> (2)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Total: <\/span><span style=\"font-weight: 400;\">26 + 26 + 10 + 2 = 64<\/span><span style=\"font-weight: 400;\"> \u2192 <\/span><i><span style=\"font-weight: 400;\">Base-64<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So Base64 is just a <\/span><b>safe text representation of binary data<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h3><b>2. Why Do We Need Base64?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Many protocols and formats (like URLs, headers, JSON, HTML attributes) are designed to work reliably with <\/span><b>text characters only<\/b><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> If we try to directly put raw binary data or special characters, things may break.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Base64 solves this by:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Converting any data into a restricted, safe character set<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Making it easy to transmit over HTTP, email, JSON, URLs, etc.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>3. How Base64 Works (Conceptual View)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">You don\u2019t need to do bit calculations manually in JavaScript (functions handle it), but understanding the logic helps:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Take binary data and break it into chunks of <\/span><b>3 bytes (24 bits)<\/b><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Split 24 bits into <\/span><b>4 groups of 6 bits<\/b><span style=\"font-weight: 400;\"> each.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Each 6-bit group can represent a value from <\/span><span style=\"font-weight: 400;\">0\u201363<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use that number to map into the Base64 character set.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">If input length is not a multiple of 3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Padding with <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> is used to make the final output a multiple of 4 characters.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Example (very simplified idea):<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Input: <\/span><span style=\"font-weight: 400;\">&#8220;Man&#8221;<\/span><span style=\"font-weight: 400;\"> \u2192 bytes of M, a, n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Output: <\/span><span style=\"font-weight: 400;\">&#8220;TWFu&#8221;<\/span><span style=\"font-weight: 400;\"> in Base64<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>4. Encoding vs Decoding<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Encoding<\/b><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> Binary \u2192 Base64 text<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">In browser: <\/span><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">In Node.js: <\/span><span style=\"font-weight: 400;\">Buffer.from(data).toString(&#8216;base64&#8217;)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Decoding<\/b><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> Base64 text \u2192 Original binary<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">In browser: <\/span><span style=\"font-weight: 400;\">atob()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">In Node.js: <\/span><span style=\"font-weight: 400;\">Buffer.from(base64, &#8216;base64&#8217;).toString(&#8216;utf8&#8217;)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">A <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> is simply a function or tool that converts Base64 back to its original form.<\/span><\/p>\n<h2><b>2. Encoding Base64 in JavaScript<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Let\u2019s start from the basics and go deep.<\/span><\/p>\n<h3><b>1. Base64 Encoding in the Browser Using <\/b><b>btoa()<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Most modern browsers provide a built-in function:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const original = &#8220;Hello, World!&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = btoa(original);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(encoded); \/\/ Output: &#8220;SGVsbG8sIFdvcmxkIQ==&#8221;<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\"> takes a <\/span><b>string<\/b><span style=\"font-weight: 400;\"> (assumed to be Latin-1 \/ ASCII) and returns its Base64 representation.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">But there\u2019s a big catch: <\/span><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\"> doesn\u2019t support full Unicode strings directly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Try this:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const text = &#8220;\u0939\u0947\u0932\u094b&#8221;; \/\/ Hindi<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = btoa(text); \/\/ \u26a0 This will throw an error<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You\u2019ll get:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8220;InvalidCharacterError: String contains an invalid character&#8221;<\/span><\/p>\n<h3><b>2. Handling Unicode Properly in the Browser<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">To safely encode any Unicode string, we must first convert it into UTF-8 bytes.<\/span><\/p>\n<p><b>Option 1: Using <\/b><b>TextEncoder<\/b><b> (modern &amp; recommended)<\/b><\/p>\n<p><span style=\"font-weight: 400;\">function base64EncodeUnicode(str) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const encoder = new TextEncoder();\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ UTF-8 encoder<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const bytes = encoder.encode(str);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Uint8Array of bytes<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0let binary = &#8220;&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0bytes.forEach((byte) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0binary += String.fromCharCode(byte);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return btoa(binary);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Encode to Base64<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const text = &#8220;\u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0941\u0928\u093f\u092f\u093e &#8220;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = base64EncodeUnicode(text);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(encoded);<\/span><\/p>\n<p><b>What\u2019s going on?<\/b><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">TextEncoder<\/span><span style=\"font-weight: 400;\"> \u2192 converts string to UTF-8 bytes.<\/span><span style=\"font-weight: 400;\">\n<p><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">We build a binary string from those bytes.<\/span><span style=\"font-weight: 400;\">\n<p><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use <\/span><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\"> to convert that binary string into Base64.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ol>\n<p><b>Option 2: Legacy trick using <\/b><b>encodeURIComponent<\/b><b> (not as clean, but common)<\/b><\/p>\n<p><span style=\"font-weight: 400;\">function base64EncodeUnicodeLegacy(str) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return btoa(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0encodeURIComponent(str).replace(\/%([0-9A-F]{2})\/g, (match, p1) =&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0String.fromCharCode(&#8220;0x&#8221; + p1)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const text = &#8220;\u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0941\u0928\u093f\u092f\u093e&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = base64EncodeUnicodeLegacy(text);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(encoded);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This works too, but <\/span><span style=\"font-weight: 400;\">TextEncoder<\/span><span style=\"font-weight: 400;\"> is more explicit and modern.<\/span><\/p>\n<ol start=\"3\">\n<li><b> Base64 Encoding in Node.js Using <\/b><b>Buffer<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">In Node.js, you <\/span><b>do not<\/b><span style=\"font-weight: 400;\"> have <\/span><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\"> or <\/span><span style=\"font-weight: 400;\">atob()<\/span><span style=\"font-weight: 400;\"> by default (unless a polyfill is used).<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> Instead, Node gives you the <\/span><span style=\"font-weight: 400;\">Buffer<\/span><span style=\"font-weight: 400;\"> class.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const data = &#8220;Hello from Node.js&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = Buffer.from(data, &#8220;utf8&#8221;).toString(&#8220;base64&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(encoded); \/\/ &#8220;SGVsbG8gZnJvbSBTb2RlLmpz&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Buffer.from(data, &#8220;utf8&#8221;)<\/span><span style=\"font-weight: 400;\"> \u2192 creates a buffer from the string<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">.toString(&#8220;base64&#8221;)<\/span><span style=\"font-weight: 400;\"> \u2192 encodes the buffer as Base64<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">You can treat this as your built-in <\/span><b>base64 encoder<\/b><span style=\"font-weight: 400;\">, and the reverse as a <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> (we\u2019ll see later).<\/span><\/p>\n<ol start=\"4\">\n<li><b> Encoding JSON Objects to Base64<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">A common use case: encode JSON payloads as Base64 for tokens, cookies, or compact transport.<\/span><\/p>\n<p><b>Browser or Node.js (same logic, just different Base64 function):<\/b><\/p>\n<p><span style=\"font-weight: 400;\">const user = {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0id: 123,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0name: &#8220;Lalit&#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0role: &#8220;admin&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">};<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Step 1: Convert to JSON string<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const jsonString = JSON.stringify(user);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Browser:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encodedBrowser = btoa(jsonString);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Node:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encodedNode = Buffer.from(jsonString, &#8220;utf8&#8221;).toString(&#8220;base64&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(encodedBrowser);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(encodedNode);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To decode, you\u2019ll parse back with <\/span><span style=\"font-weight: 400;\">JSON.parse()<\/span><span style=\"font-weight: 400;\"> after using your base64 decoder.<\/span><\/p>\n<p><b>2.5 Encoding Binary Data (Images, Files) to Base64<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Base64 is often used to embed images or files as <\/span><b>data URLs<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><b>2.5.1 Encoding a File to Base64 in Browser<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Let\u2019s say a user uploads a file and you want its Base64:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&lt;input type=&#8221;file&#8221; id=&#8221;fileInput&#8221; \/&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&lt;script&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const fileInput = document.getElementById(&#8220;fileInput&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0fileInput.addEventListener(&#8220;change&#8221;, () =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const file = fileInput.files[0];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const reader = new FileReader();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0reader.onload = () =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0const base64String = reader.result; \/\/ This is usually a data URL<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(base64String);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Example: &#8220;data:image\/png;base64,iVBORw0KGgoAAAANSUhEUg&#8230;&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0};<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0reader.readAsDataURL(file); \/\/ Reads file and encodes as Base64 data URL<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&lt;\/script&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This gives you something like:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">data:image\/png;base64,iVBORw0KGgoAAAANSUhEUg&#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you only want the pure Base64 string (without the <\/span><span style=\"font-weight: 400;\">data:&#8230;;base64,<\/span><span style=\"font-weight: 400;\"> prefix):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64Only = base64String.split(&#8220;,&#8221;)[1];<\/span><\/p>\n<h4><b>2.5.2 Encoding ArrayBuffer or Uint8Array<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">If you already have an <\/span><span style=\"font-weight: 400;\">ArrayBuffer<\/span><span style=\"font-weight: 400;\"> (e.g., from a fetch of a binary file):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function arrayBufferToBase64(buffer) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0let binary = &#8220;&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const bytes = new Uint8Array(buffer);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0bytes.forEach((b) =&gt; (binary += String.fromCharCode(b)));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return btoa(binary);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Example usage:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fetch(&#8220;image.png&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0.then((res) =&gt; res.arrayBuffer())<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0.then((buffer) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const base64 = arrayBufferToBase64(buffer);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0console.log(base64);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0});<\/span><\/p>\n<ol start=\"3\">\n<li><b> Decoding Base64 in JavaScript (Base64 Decoder)<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Now let\u2019s focus on the <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> side &#8211; taking Base64 and getting back original data.<\/span><\/p>\n<h3><b>1. Decoding Base64 in the Browser Using <\/b><b>atob()<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Basic usage:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = &#8220;SGVsbG8sIFdvcmxkIQ==&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decoded = atob(encoded);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(decoded); \/\/ &#8220;Hello, World!&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Again, <\/span><span style=\"font-weight: 400;\">atob()<\/span><span style=\"font-weight: 400;\"> expects and returns <\/span><b>Latin-1 \/ ASCII<\/b><span style=\"font-weight: 400;\"> text.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> If your original text was Unicode, you need an extra step.<\/span><\/p>\n<h3><b>2. Decoding Unicode Strings from Base64 (Browser)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Corresponding to our encoder, we will create a <\/span><b>Unicode-safe base64 decoder<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><b>Using <\/b><b>TextDecoder<\/b><span style=\"font-weight: 400;\">:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function base64DecodeUnicode(base64Str) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const binary = atob(base64Str);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Base64 \u2192 binary string<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const len = binary.length;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const bytes = new Uint8Array(len);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0for (let i = 0; i &lt; len; i++) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0bytes[i] = binary.charCodeAt(i);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const decoder = new TextDecoder(); \u00a0 \u00a0 \u00a0 \/\/ Default: UTF-8<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return decoder.decode(bytes);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Bytes \u2192 original string<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const text = &#8220;\u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0941\u0928\u093f\u092f\u093e&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = base64EncodeUnicode(text); \u00a0 \/\/ From previous section<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decoded = base64DecodeUnicode(encoded);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(decoded); \/\/ &#8220;\u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0941\u0928\u093f\u092f\u093e&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you used the legacy <\/span><span style=\"font-weight: 400;\">encodeURIComponent<\/span><span style=\"font-weight: 400;\"> trick for encoding, you can decode similarly:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function base64DecodeUnicodeLegacy(base64Str) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return decodeURIComponent(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0atob(base64Str)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.split(&#8220;&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.map((c) =&gt; &#8220;%&#8221; + c.charCodeAt(0).toString(16).padStart(2, &#8220;0&#8221;))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.join(&#8220;&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<ol start=\"3\">\n<li><b> Base64 Decoder in Node.js Using <\/b><b>Buffer<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">In Node.js, <\/span><span style=\"font-weight: 400;\">Buffer<\/span><span style=\"font-weight: 400;\"> again acts as the encoder\/decoder pair.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = &#8220;SGVsbG8gZnJvbSBTb2RlLmpz&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decoded = Buffer.from(encoded, &#8220;base64&#8221;).toString(&#8220;utf8&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(decoded); \/\/ &#8220;Hello from Node.js&#8221;<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Buffer.from(encoded, &#8220;base64&#8221;)<\/span><span style=\"font-weight: 400;\"> \u2192 interprets the input as Base64<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">.toString(&#8220;utf8&#8221;)<\/span><span style=\"font-weight: 400;\"> \u2192 converts bytes to a UTF-8 string<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">This is your <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> implementation in Node.js.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can wrap it in a helper:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function base64DecodeNode(base64Str) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return Buffer.from(base64Str, &#8220;base64&#8221;).toString(&#8220;utf8&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<ol start=\"4\">\n<li><b> Decoding Base64 JSON Payloads<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">If you encoded JSON earlier, decoding is straightforward:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Browser example<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = btoa(JSON.stringify({ id: 123, name: &#8220;Lalit&#8221; }));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const jsonString = atob(encoded);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const obj = JSON.parse(jsonString);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(obj.id); \u00a0 \/\/ 123<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(obj.name); \/\/ &#8220;Lalit&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Node.js:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = Buffer.from(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0JSON.stringify({ id: 123, name: &#8220;Lalit&#8221; }),<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0&#8220;utf8&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">).toString(&#8220;base64&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decodedJson = Buffer.from(encoded, &#8220;base64&#8221;).toString(&#8220;utf8&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const obj = JSON.parse(decodedJson);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(obj);<\/span><\/p>\n<ol start=\"5\">\n<li><b> Decoding Base64 Images in the Browser<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Assume we have a Base64 data URL and we want to show it in an <\/span><span style=\"font-weight: 400;\">&lt;img&gt;<\/span><span style=\"font-weight: 400;\"> tag:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64DataUrl = &#8220;data:image\/png;base64,iVBORw0KGgoAAAANSUhEUg&#8230;&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const img = document.createElement(&#8220;img&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">img.src = base64DataUrl;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">document.body.appendChild(img);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you have only the raw Base64 string, you can prefix it:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = &#8220;iVBORw0KGgoAAAANSUhEUg&#8230;&#8221;; \/\/ pure Base64 (no prefix)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const img = document.createElement(&#8220;img&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">img.src = `data:image\/png;base64,${base64}`;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">document.body.appendChild(img);<\/span><\/p>\n<h4><b>Convert Base64 to <\/b><b>Blob<\/b><b> or <\/b><b>File<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">function base64ToBlob(base64, contentType = &#8220;&#8221;, sliceSize = 512) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const byteCharacters = atob(base64);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0const byteArrays = [];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0for (let offset = 0; offset &lt; byteCharacters.length; offset += sliceSize) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const slice = byteCharacters.slice(offset, offset + sliceSize);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const byteNumbers = new Array(slice.length);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0for (let i = 0; i &lt; slice.length; i++) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0byteNumbers[i] = slice.charCodeAt(i);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const byteArray = new Uint8Array(byteNumbers);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0byteArrays.push(byteArray);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return new Blob(byteArrays, { type: contentType });<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><b>Usage:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = &#8220;iVBORw0KGgoAAAANSUhEUg&#8230;&#8221;; \/\/ image bytes<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const blob = base64ToBlob(base64, &#8220;image\/png&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const url = URL.createObjectURL(blob);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const img = document.createElement(&#8220;img&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">img.src = url;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">document.body.appendChild(img);<\/span><\/p>\n<ol start=\"4\">\n<li><b> What Are the Benefits of Base64?<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Base64 is not magic, but it has some serious practical advantages.<\/span><\/p>\n<h3><b>1. Safe Transmission of Binary Data Over Text-Only Channels<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Some channels (like legacy email, certain APIs, or logs) only handle <\/span><b>printable text<\/b><span style=\"font-weight: 400;\"> reliably.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> Base64 ensures:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">No control characters<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">No issues with newlines, quotes, or special symbols<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>2. Easy Embedding in HTML, CSS, and JSON<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Common use cases:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Embedding images as data URLs in HTML or CSS<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Embedding configuration or payloads in JSON<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Storing compact tokens or config in environment variables<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Example: CSS background image with Base64:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">.element {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0background-image: url(&#8220;data:image\/png;base64,iVBORw0KGgoAAAANSUhEUg&#8230;&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><b>3. Simpler Debugging and Copy\u2013Paste<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Compared to raw binary, Base64:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Can be copied\/pasted in editors, terminals, logs<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Can be quickly checked using any <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> tool<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>4. Standard and Widely Supported<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Base64 is standardized in multiple RFCs and supported across:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Browsers (<\/span><span style=\"font-weight: 400;\">btoa<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">atob<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Node.js (<\/span><span style=\"font-weight: 400;\">Buffer<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Almost all languages (Java, Python, Go, PHP, etc.)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">This makes it a good <\/span><b>interoperability layer<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<ol start=\"5\">\n<li><b> What Are the Limitations of Base64?<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Base64 is not perfect. You should know its drawbacks.<\/span><\/p>\n<h3><b>1 Increased Size (\u224833% Overhead)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Base64 makes data <\/span><b>about 33% larger<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">3 bytes \u2192 4 Base64 characters<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">So the storage and bandwidth usage increase<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">For example:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Binary image: 1 MB<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Base64 image: ~1.33 MB<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">For large files, this can be significant.<\/span><\/p>\n<h3><b>2. Not Encryption (No Real Security)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Very important point:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Base64 is <\/span><b>not<\/b><span style=\"font-weight: 400;\"> encryption. It\u2019s just encoding.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Anyone can run a <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> (online or via code) and get the original data back easily.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Do <\/span><b>not<\/b><span style=\"font-weight: 400;\"> use Base64 as a security or obfuscation mechanism.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">For real security, use proper crypto algorithms (AES, RSA, etc.) and TLS.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>3. Performance Impact for Large Data<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Encoding\/decoding large files (like videos or big images) in JavaScript (especially in browser) can be slow and memory-heavy.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">For such cases, it\u2019s better to keep data as binary streams instead of converting to Base64.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>4. URL and Filename Issues<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Base64 output may contain characters like <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">, and <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In URLs, <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> might be interpreted as space, <\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\"> as path separator, etc.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">We need URL-safe Base64 variants or encoding.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">We\u2019ll touch on URL-safe Base64 below in best practices.<\/span><\/p>\n<ol start=\"6\">\n<li><b> How to Encode Data with Base64 in JavaScript (Step by Step)<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Let\u2019s summarize practical workflows for different environments and data types.<\/span><\/p>\n<h3><b>1. Strings in Browser<\/b><\/h3>\n<p><b>ASCII-only string:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">const message = &#8220;Simple text&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = btoa(message);<\/span><\/p>\n<p><b>Unicode string (safe method):<\/b><\/p>\n<p><span style=\"font-weight: 400;\">const message = &#8220;\u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0941\u0928\u093f\u092f\u093e&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = base64EncodeUnicode(message); \/\/ from earlier function<\/span><\/p>\n<h3><b>2. Strings in Node.js<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">const message = &#8220;\u0928\u092e\u0938\u094d\u0924\u0947 \u0926\u0941\u0928\u093f\u092f\u093e&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = Buffer.from(message, &#8220;utf8&#8221;).toString(&#8220;base64&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">console.log(base64);<\/span><\/p>\n<h3><b>3. JSON Payloads<\/b><\/h3>\n<p><b>Encode:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">const payload = { id: 1, email: &#8220;user@example.com&#8221; };<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const jsonStr = JSON.stringify(payload);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Browser<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = btoa(jsonStr);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Node<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ const base64 = Buffer.from(jsonStr, &#8220;utf8&#8221;).toString(&#8220;base64&#8221;);<\/span><\/p>\n<p><b>Decode:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Browser<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decodedJsonStr = atob(base64);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const data = JSON.parse(decodedJsonStr);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Node<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ const decodedJsonStr = Buffer.from(base64, &#8220;base64&#8221;).toString(&#8220;utf8&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ const data = JSON.parse(decodedJsonStr);<\/span><\/p>\n<h3><b>4. Encoding Data for URL (URL-Safe Base64)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Sometimes you want Base64 inside URLs. You can convert to URL-safe by replacing characters:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function toUrlSafeBase64(base64Str) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return base64Str.replace(\/\\+\/g, &#8220;-&#8220;).replace(\/\\\/\/g, &#8220;_&#8221;).replace(\/=+$\/, &#8220;&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function fromUrlSafeBase64(urlSafeStr) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0let base64 = urlSafeStr.replace(\/-\/g, &#8220;+&#8221;).replace(\/_\/g, &#8220;\/&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\/\/ Add padding back if needed<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0while (base64.length % 4 !== 0) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0base64 += &#8220;=&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0return base64;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><b>Use case:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">const payload = { userId: 123 };<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const json = JSON.stringify(payload);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = btoa(json);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const urlSafe = toUrlSafeBase64(base64);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const url = `https:\/\/example.com\/reset?token=${encodeURIComponent(urlSafe)}`;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Later on server, reverse the process using your base64 decoder.<\/span><\/p>\n<ol start=\"7\">\n<li><b> Pitfalls and Best Practices<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Now let\u2019s talk about common mistakes and how to avoid them.<\/span><\/p>\n<h3><b>1. Pitfall: Assuming Base64 Is Encryption<\/b><\/h3>\n<p><b>Mistake:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\"> Storing sensitive data as Base64 and thinking it&#8217;s safe.<\/span><\/p>\n<p><b>Fix \/ Best Practice:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Understand Base64 is reversible with any base64 decoder.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use encryption (like AES) if you need security, then optionally Base64-encode the ciphertext for transport.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<ol start=\"2\">\n<li><b> Pitfall: Unicode Handling with <\/b><b>btoa<\/b><b> \/ <\/b><b>atob<\/b><\/li>\n<\/ol>\n<p><b>Mistake:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\"> Passing arbitrary Unicode text directly to <\/span><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\"> and reading from <\/span><span style=\"font-weight: 400;\">atob()<\/span><span style=\"font-weight: 400;\"> directly.<\/span><\/p>\n<p><b>Fix \/ Best Practice:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Always convert Unicode strings to bytes (<\/span><span style=\"font-weight: 400;\">TextEncoder<\/span><span style=\"font-weight: 400;\">) before <\/span><span style=\"font-weight: 400;\">btoa<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">After decoding with <\/span><span style=\"font-weight: 400;\">atob<\/span><span style=\"font-weight: 400;\">, convert the binary string back to text using <\/span><span style=\"font-weight: 400;\">TextDecoder<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<ol start=\"3\">\n<li><b> Pitfall: Using Base64 for Very Large Files in Browser<\/b><\/li>\n<\/ol>\n<p><b>Mistake:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\"> Converting large images\/videos entirely into Base64 in the browser, causing memory and performance issues.<\/span><\/p>\n<p><b>Fix \/ Best Practice:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Prefer streaming or direct binary transfer where possible.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use URLs (e.g., object URLs) instead of data URLs for large assets.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<ol start=\"4\">\n<li><b> Pitfall: Forgetting About Size Overhead<\/b><\/li>\n<\/ol>\n<p><b>Mistake:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\"> Embedding lots of Base64 images in HTML or CSS and wondering why page size is huge.<\/span><\/p>\n<p><b>Fix \/ Best Practice:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use Base64 only when advantageous (e.g., small inline icons, avoiding extra HTTP requests).<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">For big images, serve them as normal image files via URLs\/CDN.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<ol start=\"5\">\n<li><b> Pitfall: Ignoring URL-Safety<\/b><\/li>\n<\/ol>\n<p><b>Mistake:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\"> Sending raw Base64 strings in URLs and facing issues due to <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">, or <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><b>Fix \/ Best Practice:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use URL-safe Base64 variants (replace <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\"> and trim <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\">).<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Or always wrap tokens with <\/span><span style=\"font-weight: 400;\">encodeURIComponent()<\/span><span style=\"font-weight: 400;\"> \/ <\/span><span style=\"font-weight: 400;\">decodeURIComponent()<\/span><span style=\"font-weight: 400;\"> when using URLs.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<ol start=\"6\">\n<li><b> Pitfall: Double Encoding<\/b><\/li>\n<\/ol>\n<p><b>Mistake:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\"> Encoding the same data multiple times by mistake:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">original \u2192 Base64 \u2192 again Base64 \u2192 broken<\/span><\/p>\n<p><b>Fix \/ Best Practice:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Keep track of whether your data is already encoded.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Have clear naming, like:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">data<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">dataBase64<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">dataDecoded<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><b> Frequently Asked Questions (FAQ)<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Let\u2019s close with a FAQ section focused around <\/span><b>Base64<\/b><span style=\"font-weight: 400;\"> and <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> concepts in JavaScript.<\/span><\/p>\n<h3><b>Q1. What is a base64 decoder in JavaScript?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">A <\/span><b>base64 decoder<\/b><span style=\"font-weight: 400;\"> in JavaScript is any function that takes a Base64-encoded string and returns the original data (usually text or bytes).<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In browsers: <\/span><span style=\"font-weight: 400;\">atob(base64String)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In Node.js: <\/span><span style=\"font-weight: 400;\">Buffer.from(base64String, &#8220;base64&#8221;)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Example (browser):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decoded = atob(&#8220;SGVsbG8sIFdvcmxkIQ==&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example (Node):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decoded = Buffer.from(&#8220;SGVsbG8sIFdvcmxkIQ==&#8221;, &#8220;base64&#8221;).toString(&#8220;utf8&#8221;);<\/span><\/p>\n<h3><b>Q2. Is Base64 encoding the same as encryption?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">No.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> Base64 is <\/span><b>not<\/b><span style=\"font-weight: 400;\"> encryption, it is just an encoding.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Purpose: make binary data text-safe<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Anyone can decode it with a base64 decoder<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">It does <\/span><b>not<\/b><span style=\"font-weight: 400;\"> protect confidentiality<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">For security, you must use encryption algorithms.<\/span><\/p>\n<h3><b>Q3. Why does Base64 increase string size?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Because Base64 represents 3 bytes of binary data using 4 characters (each from 64 possibilities).<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">3 bytes (24 bits) \u2192 4 x 6 bits = 24 bits<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">So output grows by about 33%.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>Q4. When should I use Base64?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Use Base64 when:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You need to embed binary data in text-based structures (JSON, HTML, XML).<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You want to avoid issues with binary or special characters over protocols that expect text.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You want to quickly copy\/paste or log data safely.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><b>Avoid it for:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Very large files where overhead and performance matter.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Security use-cases (it\u2019s not encryption).<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>Q5. What is the difference between <\/b><b>btoa<\/b><b>\/<\/b><b>atob<\/b><b> and <\/b><b>Buffer<\/b><b>?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">btoa<\/span><span style=\"font-weight: 400;\"> \/ <\/span><span style=\"font-weight: 400;\">atob<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Available in browsers<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Work on strings assuming ASCII\/Latin-1<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Need extra steps for Unicode<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Buffer<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Node.js feature<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Works directly with bytes<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Can encode\/decode using <\/span><span style=\"font-weight: 400;\">&#8220;base64&#8221;<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">&#8220;utf8&#8221;<\/span><span style=\"font-weight: 400;\"> easily<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\/\/ Browser<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = btoa(&#8220;Hello&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Node<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64Node = Buffer.from(&#8220;Hello&#8221;, &#8220;utf8&#8221;).toString(&#8220;base64&#8221;);<\/span><\/p>\n<h3><b>Q6. How do I decode a Base64 string that represents JSON?<\/b><\/h3>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Decode Base64 to string using a base64 decoder.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Parse JSON.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Browser:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = btoa(JSON.stringify({ id: 1 }));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decodedJsonStr = atob(encoded);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const obj = JSON.parse(decodedJsonStr);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Node:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const encoded = Buffer.from(JSON.stringify({ id: 1 }), &#8220;utf8&#8221;).toString(&#8220;base64&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const decodedJsonStr = Buffer.from(encoded, &#8220;base64&#8221;).toString(&#8220;utf8&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const obj = JSON.parse(decodedJsonStr);<\/span><\/p>\n<h3><b>Q7. How do I decode a Base64 image and show it in the browser?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">If you have a Base64 string (without prefix):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const base64 = &#8220;iVBORw0KGgoAAAANSUhEUg&#8230;&#8221;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const img = document.createElement(&#8220;img&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">img.src = `data:image\/png;base64,${base64}`;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">document.body.appendChild(img);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you want a file-like object:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use <\/span><span style=\"font-weight: 400;\">base64ToBlob<\/span><span style=\"font-weight: 400;\"> (shown earlier), then create an object URL.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>Q8. What is URL-safe Base64?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">URL-safe Base64 replaces characters that can cause issues in URLs:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> \u2192 <\/span><span style=\"font-weight: 400;\">&#8211;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\"> \u2192 <\/span><span style=\"font-weight: 400;\">_<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Optional: remove trailing <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Many APIs and JWTs use URL-safe Base64.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can convert using helper functions like <\/span><span style=\"font-weight: 400;\">toUrlSafeBase64<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">fromUrlSafeBase64<\/span><span style=\"font-weight: 400;\"> from earlier sections.<\/span><\/p>\n<h3><b>Q9. Can Base64 be used as a checksum or validation?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">No.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> Base64 does not verify integrity. It does not detect tampering.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For validation:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use checksums (MD5, SHA-256)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Or signed tokens (HMAC, JWT with signature)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<h3><b>Q10. Is it safe to use online base64 decoder tools?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">For <\/span><b>non-sensitive<\/b><span style=\"font-weight: 400;\"> data, yes, it\u2019s fine.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> For <\/span><b>sensitive<\/b><span style=\"font-weight: 400;\"> data (passwords, tokens, private keys):<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Avoid pasting into online tools.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use local tools or write your own base64 decoder in JavaScript\/Node instead.<\/span><\/li>\n<\/ul>\n<h4><b>Conclusion<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Base64 encoding and decoding play an essential role in modern web and application development. Whether you are working with APIs, transmitting binary data, handling JSON payloads, or embedding images directly into HTML\/CSS, Base64 provides a reliable and universally supported way to convert raw data into a safe, text-based format.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this article, we explored:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">What Base64 encoding and decoding actually are<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">How the Base64 algorithm works behind the scenes<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">How to encode and decode strings in JavaScript using <\/span><span style=\"font-weight: 400;\">btoa()<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">atob()<\/span><span style=\"font-weight: 400;\">, and <\/span><span style=\"font-weight: 400;\">Buffer<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">How to properly handle Unicode text, JSON objects, images, files, and binary data<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Key benefits and limitations of using Base64<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Real examples and best practices developers must follow<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Common mistakes to avoid while implementing Base64 in JavaScript<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">One important takeaway is that <\/span><b>Base64 is not encryption<\/b><span style=\"font-weight: 400;\">. It does not provide security or protect sensitive information. It simply converts binary data into a text format that can be safely stored, transferred, or embedded. For security, encryption algorithms must be used &#8211; not Base64.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you apply the techniques and knowledge shared in this article, you will be able to confidently implement Base64 encoding and decoding in any JavaScript environment, whether in the browser, Node.js, or hybrid applications.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Base64 is a small concept, but it has a massive impact on how data flows across the web. Understanding it deeply makes you a better, more reliable, and more efficient developer.<\/span><\/p>\n<p><strong>Also read:-<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/utho.com\/blog\/abstraction-in-java-and-oops\/\">What is Abstraction in Java and OOPs?<\/a><\/li>\n<li><a href=\"https:\/\/utho.com\/blog\/java-collection-framework-benefits-types-diagram\/\">What is the Collection Framework in Java?<\/a><\/li>\n<li><a href=\"https:\/\/utho.com\/blog\/overloading-vs-overriding-in-java\/\">Key Differences Between Method Overloading and Method Overriding in Java<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Base64 is one of those things every developer uses, but very few truly understand. You see Base64 strings everywhere &#8211; inside JWT tokens, API payloads, cookies, image previews, and even those long \u201csecret-looking\u201d strings you often copy\u2013paste during integrations. It has become a universal way to safely transmit data across systems that were originally designed [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":15056,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-15055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Base64 Encoding and Decoding in JavaScript Guide<\/title>\n<meta name=\"description\" content=\"Learn how to encode and decode Base64 strings in JavaScript with clear examples using btoa, atob, and modern methods for web developers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Base64 Encoding and Decoding in JavaScript Guide\" \/>\n<meta property=\"og:description\" content=\"Learn how to encode and decode Base64 strings in JavaScript with clear examples using btoa, atob, and modern methods for web developers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Utho\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/uthocloud\" \/>\n<meta property=\"article:published_time\" content=\"2025-12-20T08:39:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-23T09:05:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/utho.com\/blog\/wp-content\/uploads\/Encoding-and-Decoding-Base64-Strings-in-JavaScript-Explained.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"556\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Umesh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@uthocloud\" \/>\n<meta name=\"twitter:site\" content=\"@uthocloud\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Umesh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/\"},\"author\":{\"name\":\"Umesh\",\"@id\":\"https:\/\/utho.com\/blog\/#\/schema\/person\/f213e3fcf1ea5603ab66197a9c960b3c\"},\"headline\":\"Encoding and Decoding Base64 Strings in JavaScript Explained\",\"datePublished\":\"2025-12-20T08:39:05+00:00\",\"dateModified\":\"2025-12-23T09:05:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/\"},\"wordCount\":3223,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/utho.com\/blog\/#organization\"},\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/\",\"url\":\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/\",\"name\":\"Base64 Encoding and Decoding in JavaScript Guide\",\"isPartOf\":{\"@id\":\"https:\/\/utho.com\/blog\/#website\"},\"datePublished\":\"2025-12-20T08:39:05+00:00\",\"dateModified\":\"2025-12-23T09:05:47+00:00\",\"description\":\"Learn how to encode and decode Base64 strings in JavaScript with clear examples using btoa, atob, and modern methods for web developers.\",\"breadcrumb\":{\"@id\":\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/utho.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Encoding and Decoding Base64 Strings in JavaScript Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/utho.com\/blog\/#website\",\"url\":\"https:\/\/utho.com\/blog\/\",\"name\":\"Utho\",\"description\":\"Tutorials Guides for Linux, Windows and Developers\",\"publisher\":{\"@id\":\"https:\/\/utho.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/utho.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/utho.com\/blog\/#organization\",\"name\":\"Utho\",\"url\":\"https:\/\/utho.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/utho.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/utho.com\/blog\/wp-content\/uploads\/utho_logo_blue.png\",\"contentUrl\":\"https:\/\/utho.com\/blog\/wp-content\/uploads\/utho_logo_blue.png\",\"width\":1147,\"height\":446,\"caption\":\"Utho\"},\"image\":{\"@id\":\"https:\/\/utho.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/uthocloud\",\"https:\/\/twitter.com\/uthocloud\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/utho.com\/blog\/#\/schema\/person\/f213e3fcf1ea5603ab66197a9c960b3c\",\"name\":\"Umesh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/utho.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/afa76ed351f7257e667140e6a5ad997a47e4c0c9e09cb1f81f91e75f72906613?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/afa76ed351f7257e667140e6a5ad997a47e4c0c9e09cb1f81f91e75f72906613?s=96&d=mm&r=g\",\"caption\":\"Umesh\"},\"url\":\"https:\/\/utho.com\/blog\/author\/profito\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Base64 Encoding and Decoding in JavaScript Guide","description":"Learn how to encode and decode Base64 strings in JavaScript with clear examples using btoa, atob, and modern methods for web developers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Base64 Encoding and Decoding in JavaScript Guide","og_description":"Learn how to encode and decode Base64 strings in JavaScript with clear examples using btoa, atob, and modern methods for web developers.","og_url":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/","og_site_name":"Utho","article_publisher":"https:\/\/www.facebook.com\/uthocloud","article_published_time":"2025-12-20T08:39:05+00:00","article_modified_time":"2025-12-23T09:05:47+00:00","og_image":[{"width":1024,"height":556,"url":"https:\/\/utho.com\/blog\/wp-content\/uploads\/Encoding-and-Decoding-Base64-Strings-in-JavaScript-Explained.jpg","type":"image\/jpeg"}],"author":"Umesh","twitter_card":"summary_large_image","twitter_creator":"@uthocloud","twitter_site":"@uthocloud","twitter_misc":{"Written by":"Umesh","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#article","isPartOf":{"@id":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/"},"author":{"name":"Umesh","@id":"https:\/\/utho.com\/blog\/#\/schema\/person\/f213e3fcf1ea5603ab66197a9c960b3c"},"headline":"Encoding and Decoding Base64 Strings in JavaScript Explained","datePublished":"2025-12-20T08:39:05+00:00","dateModified":"2025-12-23T09:05:47+00:00","mainEntityOfPage":{"@id":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/"},"wordCount":3223,"commentCount":0,"publisher":{"@id":"https:\/\/utho.com\/blog\/#organization"},"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/","url":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/","name":"Base64 Encoding and Decoding in JavaScript Guide","isPartOf":{"@id":"https:\/\/utho.com\/blog\/#website"},"datePublished":"2025-12-20T08:39:05+00:00","dateModified":"2025-12-23T09:05:47+00:00","description":"Learn how to encode and decode Base64 strings in JavaScript with clear examples using btoa, atob, and modern methods for web developers.","breadcrumb":{"@id":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/utho.com\/blog\/encoding-decoding-base64-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/utho.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Encoding and Decoding Base64 Strings in JavaScript Explained"}]},{"@type":"WebSite","@id":"https:\/\/utho.com\/blog\/#website","url":"https:\/\/utho.com\/blog\/","name":"Utho","description":"Tutorials Guides for Linux, Windows and Developers","publisher":{"@id":"https:\/\/utho.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/utho.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/utho.com\/blog\/#organization","name":"Utho","url":"https:\/\/utho.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/utho.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/utho.com\/blog\/wp-content\/uploads\/utho_logo_blue.png","contentUrl":"https:\/\/utho.com\/blog\/wp-content\/uploads\/utho_logo_blue.png","width":1147,"height":446,"caption":"Utho"},"image":{"@id":"https:\/\/utho.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/uthocloud","https:\/\/twitter.com\/uthocloud"]},{"@type":"Person","@id":"https:\/\/utho.com\/blog\/#\/schema\/person\/f213e3fcf1ea5603ab66197a9c960b3c","name":"Umesh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/utho.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/afa76ed351f7257e667140e6a5ad997a47e4c0c9e09cb1f81f91e75f72906613?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/afa76ed351f7257e667140e6a5ad997a47e4c0c9e09cb1f81f91e75f72906613?s=96&d=mm&r=g","caption":"Umesh"},"url":"https:\/\/utho.com\/blog\/author\/profito\/"}]}},"_links":{"self":[{"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/posts\/15055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/comments?post=15055"}],"version-history":[{"count":2,"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/posts\/15055\/revisions"}],"predecessor-version":[{"id":15060,"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/posts\/15055\/revisions\/15060"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/media\/15056"}],"wp:attachment":[{"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/media?parent=15055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/categories?post=15055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/utho.com\/blog\/wp-json\/wp\/v2\/tags?post=15055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}