Skip to content

JavaScript Obfuscator

Obfuscated code —
Original characters
—
Output characters
—
Strings encoded
—
Comments removed
—

Paste JavaScript and the obfuscator removes comments, collapses indentation and rewrites each quoted string as escape codes, so var s = "Hi"; becomes var s="x48x69";. The code runs exactly as before, but text searches for keywords, URLs or messages inside the file no longer match at a glance.

About this tool

A shipped script often carries strings you would rather not hand over in plain sight: API paths, licence checks, error wording or internal names. This obfuscator gives a light layer of cover without a build step. It strips line and block comments, squeezes spaces and blank lines, and turns every single- or double-quoted string into hexadecimal or Unicode escapes that the JavaScript engine decodes back at run time. Template literals and regular expressions are copied unchanged so their behaviour cannot shift. Line breaks stay in place, which keeps automatic semicolon insertion working on code written without semicolons. The output also reports how many strings were encoded and how the size changed. Keep in mind this is reversible: anyone who pastes the result into a console or a formatter can read the strings again, so it deters casual copying, not a determined reader.

How to use it

  1. Paste or open your script

    Paste JavaScript into the box or open a .js or .txt file from your device; it is read locally.

  2. Choose string encoding

    Leave the switch on to hex-encode string literals, or turn it off to only strip comments and whitespace.

  3. Check the counts

    Compare original and output characters, and see how many strings and comments were processed.

  4. Copy the output

    Copy the obfuscated code and run your tests on it before replacing the original file.

Examples

A short string

JavaScript code
var s = "Hi";
Encode string literals as hex escapes
Yes

Result Obfuscated code: var s="\x48\x69";
Original characters: 13
Output characters: 17
Strings encoded: 1
Comments removed: 0

  1. Removed 0 comments and collapsed spaces and blank lines; line breaks are kept so automatic semicolons still work.
  2. Rewrote 1 string literal as \xHH or \uHHHH escapes; template literals and regular expressions are copied unchanged.
  3. Size went from 13 to 17 characters.

The letters H and i become their ASCII hex codes, and the spaces around = are dropped.

A function with comments

JavaScript code
// say hello function hi(name) { /* greet */ return 'Hey ' + name; }
Encode string literals as hex escapes
Yes

Result Obfuscated code: function hi(name){
return'\x48\x65\x79\x20'+name;
}
Original characters: 72
Output characters: 51
Strings encoded: 1
Comments removed: 2

  1. Removed 2 comments and collapsed spaces and blank lines; line breaks are kept so automatic semicolons still work.
  2. Rewrote 1 string literal as \xHH or \uHHHH escapes; template literals and regular expressions are copied unchanged.
  3. Size went from 72 to 51 characters.

Both comments go, indentation collapses, and the string 'Hey ' turns into four hex escapes including the trailing space.

Minify only, strings kept

JavaScript code
const msg = 'ok'; // done
Encode string literals as hex escapes
No

Result Obfuscated code: const msg='ok';
Original characters: 26
Output characters: 15
Strings encoded: 0
Comments removed: 1

  1. Removed 1 comment and collapsed spaces and blank lines; line breaks are kept so automatic semicolons still work.
  2. String literals were left readable.
  3. Size went from 26 to 15 characters.

With string encoding switched off, the output is a plain minified line with the comment removed.

When not to use it

  • Protecting secrets such as API keys, since escaped strings decode instantly in any console.
  • Shrinking files for production, because hex escapes make strings about four times longer than a minifier would.
  • Code that relies on Function.toString output or on comments such as licence headers that must stay.

Common mistakes

  • Expecting variable and function names to be renamed; this tool leaves identifiers as written.
  • Shipping the output without running the test suite, especially on code with unusual regular expressions.
  • Assuming obfuscated code is secure when browser dev tools can pretty-print and decode it.

Frequently asked questions

Will the obfuscated code behave the same?

Yes for ordinary scripts. Escape sequences such as \x48 are decoded by the engine into the same characters, comments have no runtime effect, and line breaks are preserved so semicolon insertion is unchanged. Run your tests anyway, because a regular expression in an unusual position may be read as division.

Why are template literals not encoded?

Backtick strings can hold ${} expressions with their own code inside. Rewriting them character by character could break those expressions, so they are copied exactly as written.

Does it rename variables?

No. Identifier renaming needs a full parser that tracks scopes, exports and globals. This tool works on comments, whitespace and string literals only, so variable and function names stay readable.

Why is the output bigger than my original?

Each encoded character takes four characters as \xHH or six as \uHHHH. A file with many strings can grow even after comments and indentation are removed. Turn the encoding switch off for a size reduction only.

Can someone reverse this?

Easily. Pasting an encoded string into a browser console prints the original text. Treat the output as a deterrent against skimming and simple text searches, not as protection for credentials or business logic.

Is my code uploaded anywhere?

No. Processing happens in your browser, including files you open, and the code is not saved when you leave the page.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, October 25). JavaScript Obfuscator. Tools Directory. Retrieved October 26, 2026, from https://tools.milunir.com/developer-tools/programming-language-tools/javascript-obfuscator/

MLA

Tools Directory Editorial Team. “JavaScript Obfuscator.” Tools Directory, 25 Oct. 2026, https://tools.milunir.com/developer-tools/programming-language-tools/javascript-obfuscator/. Accessed 26 Oct. 2026.

Chicago

Tools Directory Editorial Team. “JavaScript Obfuscator.” Tools Directory. Last modified October 25, 2026. Accessed October 26, 2026. https://tools.milunir.com/developer-tools/programming-language-tools/javascript-obfuscator/.

Link<a href="https://tools.milunir.com/developer-tools/programming-language-tools/javascript-obfuscator/">JavaScript Obfuscator – Tools Directory</a>