JavaScript to Base64

A config file needs a script field without quote-escaping headaches. Paste the source, copy the Base64 string, drop the payload into JSON or a header. Encoding runs locally while you type.

JavaScript source

Paste or type code. Output refreshes after a short pause.

Lines
0
Characters
0

Base64 output

Standard alphabet (A-Z, a-z, 0-9, +, /). No line breaks added.

Source bytes
0 bytes
Encoded bytes
0 bytes
Overhead
0%
Encoding
UTF-8

Base64 carries bytes through text channels

Base64 turns arbitrary bytes into ASCII letters, digits, plus two symbols. Email gateways, JSON fields, query strings, plus older APIs expect text. Raw JavaScript with quotes, backslashes, or emoji breaks those transports unless you escape every special character.

Encoding is reversible. Anyone with atob() or the Base64 to JavaScript page reads the source back in seconds. Do not treat the output as secrecy.

Not obfuscation

Teams sometimes paste encoded scripts hoping reviewers skip them. Security reviewers decode Base64 on sight. For name mangling or control-flow hiding, open the JavaScript Obfuscator instead. This page only changes representation, not behavior or readability after decode.

Where a Base64 JS string shows up in real work

Production sites rarely ship executable logic as Base64. Browsers cache external .js files; inline encoded blobs bypass cache, inflate HTML weight, plus fight Content-Security-Policy rules on script-src.

Pick the right encoder for the job

GoalThis pageBetter fit
Hide logic from end usersNoObfuscator (still not encryption)
UTF-8 JavaScript into JSONYesNone needed
Plain text, no JS syntaxOverkillText to Base64
Decode a partner payloadWrong directionBase64 to JavaScript
Check syntax before encodingNo validationJavaScript Validator

What happens when you paste

The browser treats your editor text as a UTF-8 string, not as executable code. No parsing step runs. Syntax errors in the source still encode faithfully because the tool works on characters, not an AST.

1. UTF-8 bytes
encodeURIComponent turns Unicode code points into percent-encoded bytes. Emoji in a template literal survive this step.
2. Binary string
unescape maps those bytes into a Latin-1 string btoa accepts. This pattern is the standard browser workaround for non-ASCII source.
3. Base64 alphabet
btoa emits the familiar A–Z / a–z / 0–9 / + / / stream with = padding when needed.

Load the sample button to watch a short ES6 file grow into a single line. Copy the output, paste into the decode page, you should recover the original text byte for byte.

Size numbers below the output panel

Base64 expands binary data by roughly one third. A 300-byte script becomes about 400 characters in the encoded form. The overhead row compares Blob sizes of source versus output so you see the penalty before pasting into a ticket or config file.

Very large bundles (hundreds of kilobytes) still encode, but the textarea slows down on weak hardware. Minified vendor files belong on disk or in a build step, not inside a browser textarea.

Unicode, minified files, plus odd line endings

Windows CRLF endings encode as two bytes per newline. Unix LF uses one. The round trip preserves whichever style you pasted. Minified one-line webpack output produces one very long Base64 line with no internal breaks, which is normal.

Source maps, license comments, plus non-Latin identifiers all encode. Nothing strips comments or renames symbols. Run the JavaScript Beautifier first if you want readable source before encoding for documentation screenshots.

Decode pattern you will see in the wild

const source = atob('Zm9vYmFy');const fn = new Function(source);fn();

Patterns like this appear in legacy snippets. Modern codebases prefer module imports or fetched files. If you receive an encoded block from an unknown sender, decode in a sandbox, read the source on the JavaScript Viewer, then decide whether to run anything.

Nothing uploads

Encoding uses built-in browser APIs only. Your paste never leaves the tab. Clear both panels when you finish on a shared machine. Download writes a local .txt file; delete afterward if the script is sensitive.

Questions about encoding JavaScript as Base64

Accuracy, limits, privacy, plus what to open next.

Does Base64 hide my JavaScript?

No. Base64 is encoding, not encryption. Anyone copies the string, runs atob(), or uses the Base64 to JavaScript decoder, and reads your source immediately.

Will this page run or validate my code?

No. Characters are encoded as-is. Syntax errors still produce valid Base64. Use the JavaScript Validator if you need parse errors with line numbers before shipping.

Why is the encoded string longer than the source?

Base64 packs three bytes into four ASCII characters. Expect about 33 percent growth. The stats row under the output shows exact byte counts for your paste.

Does emoji or non-English text encode correctly?

Yes. The tool uses UTF-8 through encodeURIComponent before btoa. Decode with the same UTF-8 path on the way back to recover the exact characters.

Is URL-safe Base64 supported?

This page outputs standard Base64 with + and / characters. For query strings, replace those symbols or run the result through the <a href="https://toolexe.com/security/normalize-base64">Normalize Base64</a> tool after encoding.

Is my code sent to a server?

No. Conversion runs entirely in your browser. No upload endpoint exists on this page.

How do I reverse the encoding?

Copy the output to the Base64 to JavaScript decoder, or call atob() in your own script. You should get the original source text back.

What file size works well in the textarea?

Snippets up to a few dozen kilobytes feel instant. Entire minified frameworks make the page sluggish. Encode large artifacts in a local build script instead.