JavaScript obfuscator
Semantics-preserving JavaScript obfuscation on a hand-written lexer: string literals become hex escapes, non-negative integer literals become 0x hex, the first character of identifiers becomes a Unicode escape, comments are dropped, and an optional harmless dead-code declaration can be prepended. Nothing is minified or changed in behaviour; regexes and template strings are left intact.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Obfuscated output
Semantics preserved, not minified; whitespace is normalised but line breaks are kept
Paste JavaScript source to obfuscate it
What this tool does
- Obfuscate on a hand-written lexer while keeping semantics: string literals become hex escapes, plain integer literals become 0x hex, the first character of identifiers becomes a Unicode escape, comments are dropped and an optional harmless dead-code line is prepended.
- The output can be pasted back into an editor or a console and run: because the token-by-token rebuild keeps the original line breaks, code that relies on automatic semicolon insertion (ASI) is not squashed into one line and broken.
- Five independent switches make single-purpose runs easy — comments only, strings only — and let you compare character counts before and after.
- Useful for making demo code, homework or front-end scripts less readable; everything runs locally and your code is never uploaded.
Example
Input
// 计算总和
const answer = 42;
const name = "kit";
function add(a, b) {
return a + b;
}
add(answer, 8);Output
void 0;
const answer = 0x2a ;
const name = "\x6b\x69\x74" ;
function add ( a , b ) {
return a + b ;
}
add ( answer , 8 ) ;Real output for that source with the defaults (escape strings, hex numbers, drop comments, dead-code banner; identifier escaping off): the comment disappears, 42 becomes 0x2a and "kit" becomes "\x6b\x69\x74", while line breaks and statement structure stay put.
Frequently asked questions
What exactly does it transform?
Five things, all cosmetic: 1) string literals → hex escapes per character ("kit" → "\x6b\x69\x74", while strings that already contain a backslash escape are left alone so \n does not balloon into \x5c\x6e); 2) plain integer literals → hex (42 → 0x2a; only /^\d+$/ values ≥ 10, so decimals, exponents, 10n and 0xff are untouched); 3) the first character of identifiers → a Unicode escape (document → \u0064ocument, off by default); 4) line and block comments removed; 5) an optional void 0; dead-code line prepended.
Is this encryption? Can it protect my API keys?
No on both counts. It is a reversible rewrite: any formatter — or a human — undoes it instantly, string constants still exist verbatim in the output (just as \x escapes) and the character count often grows. It does not flatten control flow, split string arrays, rename variables or encrypt anything. Never ship keys, tokens or sensitive logic in front-end code and rely on this to hide them: front-end code is always visible to whoever receives it.
Why is the output not a single line? Could it break my code?
The output is rebuilt token by token: at most one space between tokens, and a line break wherever the original had one. That is deliberate — squashing `const a = 1` and the next line `function f(){}` into one line turns into a syntax error because of automatic semicolon insertion (ASI). So it normalises whitespace rather than minifying, and the output can be longer than the input. Paste the result into an editor and run it before shipping.
Can regexes, template literals or comments inside strings be damaged?
No. The lexer recognises strings (with escapes), template literals (including nested ${}), regex literals (deciding whether a `/` starts a regex or is division from the previous token) and comments separately, so the slash inside `/ab\/c/g`, a “//” inside a string and a ${} inside a template are never mistaken for comments or separators. Tokens recognised as regex or template literals only take part in whitespace normalisation; their contents are never rewritten.
When does it fail?
Empty input (or whitespace only) raises empty-input; an unterminated string, template literal or block comment (a /* without its */) raises invalid-js, telling you the problem is lexical and refusing to emit half a result; a non-boolean option raises invalid-options. The input must be a string, otherwise invalid-input.
Is my code uploaded?
No. Tokenizing and rewriting happen locally in the browser with no network requests and no storage writes; closing the page discards everything.
Keywords:JavaScript obfuscatorjs_huixiaoofflinedeterministic