How to Obfuscate JavaScript
This tool makes JavaScript harder to read by renaming the variables inside your functions, encoding the text in your strings, and squeezing the code onto one line. It reads your code with the Babel parser and only rewrites the syntax tree, so the result still runs exactly the same. Obfuscation is a deterrent, not a lock: anyone can paste the output into the JavaScript Deobfuscator or a beautifier and read it back, so keep real secrets on a server.
Paste or upload your JavaScript
Any plain JavaScript works, including ES modules and React JSX.
Example: a small function before obfuscating
function greet(name) {
const message = "Hello, " + name;
return message;
}Pick a protection level and read the result
Each level builds on the one before it. Here is the same function at each level — note how greet stays readable (it is a top-level name that other code might call) while the parameter and the local variable are renamed.
\x escapesExample: the same function, obfuscated
// Light
function greet(_0x2){const _0x3="Hello, "+_0x2;return _0x3;}
// Medium
function greet(_0x2){const _0x3="\x48\x65\x6c\x6c\x6f\x2c\x20"+_0x2;return _0x3;}
// Heavy
const _0x4=["\x48\x65\x6c\x6c\x6f\x2c\x20"];function greet(_0x2){const _0x3=_0x4[0]+_0x2;return _0x3;}All three run the same as the original: greet("Ann") still returns "Hello, Ann".
Copy or download it
Frequently Asked Questions
What does this obfuscator actually change?
Three things, depending on the level you pick: it renames variables that are local to a function, it re-encodes the text inside string literals, and it removes comments and whitespace to put the code on one line. Everything else is left exactly as you wrote it — top-level names, object property names, numbers, regular expressions and template literals — so the code keeps working. Your code is read with Babel's parser first and only the syntax tree is transformed, never the raw text, so it won't split a string at the wrong place or mangle a regex.
What do the Light, Medium and Heavy levels do?
Light renames local variables (for example a parameter name becomes _0x2) and compacts the code. Medium does that and also encodes the characters inside strings as \x escapes, so "Notebook" becomes "\x4e\x6f\x74\x65\x62\x6f\x6f\x6b" — the same string, just harder to read. Heavy does everything Medium does and then collects those strings into one array at the top of the file and refers to each by its position. All three produce code that runs identically to the original.
Will the obfuscated code still behave exactly the same?
That is the whole point, and it is built that way. Renaming only touches names that are local to a function and updates every reference to them through Babel’s scope analysis, so nothing is left dangling. Encoded strings decode back to the identical value. Numbers are never rewritten: 8901240544102066246, 14.50 and 0x1F all stay exactly as typed, with no rounding. If your code uses eval or a with statement, variable renaming is skipped (because those can look a name up by its text), and the output tells you so.
Is obfuscation a form of security?
No. Obfuscation is not encryption. It makes code slower to read, but it still runs in the browser, so anyone determined can paste it into a beautifier or a deobfuscator and get something readable back. Treat it as a speed bump, not a lock. Keep real secrets — API keys, passwords, licensing checks — on a server, not in client-side JavaScript. And for the same reason, never run obfuscated code from a source you don't trust.
What does this tool deliberately not do?
It does not flatten control flow into switch statements, inject dead code, add a domain lock, or add self-defending / anti-debugging tricks. Those techniques are easy to describe and hard to get right: they often break real code or just give a false sense of safety. This tool sticks to transformations that keep the output provably runnable. If you need heavier protection, a build-step tool such as the javascript-obfuscator npm package does more — at the cost of larger, slower output.
Why are my top-level functions and property names left readable?
A function or variable declared at the top level might be called from another <script> tag, imported by another file, or referenced by name somewhere this tool can’t see, so renaming it could break your page. Object property names (obj.total, the keys in { price: 1 }) aren’t variables either — they’re part of your data shape. Renaming only the names that live inside a function keeps the result correct. If you want top-level names gone too, wrap your code in a module or an IIFE first.
Is my code uploaded anywhere?
No. The obfuscation runs entirely in your browser; the code is not sent to our server and nothing is kept. Reload the page and the editor is empty again.
Related tools: the JavaScript Minifier shrinks code without renaming anything, the JavaScript Formatter makes it readable, and the JavaScript Deobfuscator helps unpick already-obfuscated code.
Related Tools
JavaScript Formatter
Format and beautify JavaScript code online with proper indentation and structure
JavaScript Minifier
Minify and compress JavaScript code online for production deployment and optimization
JavaScript Fixer
Fix broken JavaScript automatically, repair syntax errors, missing brackets, and malformed code
JavaScript Beautifier
Format and beautify JavaScript code with proper indentation
JavaScript Compressor
Advanced compression with multiple optimization levels
JavaScript Validator
Validate JavaScript syntax and detect errors with detailed reporting