Minified JavaScript is one long line with every optional byte removed. That is correct for shipping and impossible to read. Formatting it is the first step to understanding a bundle you did not write — a third-party widget, a script you inherited, or your own build output when something is wrong with it.
How to use the JS Beautifier
- Paste your JavaScript, or load a .js file
- Choose an indent width — 2 spaces, 4 spaces or tabs
- Click Beautify to format it, or Minify to strip it back down
- Copy the result or download it
Why a naive formatter corrupts code
The obvious approach — add a newline after every ; and { — breaks on the first string that contains one. This is valid JavaScript:
const t = "function x(){return 1}";A regex-based formatter reformats the inside of that string, changing the data. The same applies to template literals, comments and regular expressions. A regex containing a quote — s.replace(/"/g, '"') — breaks naive scanners particularly badly, because the lone double quote looks like the start of a string.
This formatter tokenises first: it walks the source identifying strings, template literals, comments and regex literals, and only touches whitespace between tokens. Everything inside a literal is passed through byte for byte.
What formatting can and cannot recover
Indentation and line breaks come back. Structure becomes visible again — you can see which braces pair up, where functions begin and end, and how deeply things nest.
What is gone for good is anything the minifier removed rather than compressed. Comments are deleted, not hidden. More significantly, most minifiers rename local variables to single letters, and that mapping is not stored anywhere. A formatted bundle is readable but anonymous — function a(b,c){...} tells you the shape, not the intent.
If the build published a source map (a //# sourceMappingURL comment at the end of the file), that is a far better route: it restores original names, files and line numbers. Formatting is the fallback when no map exists.
Source maps, and the proper way back to readable code
Beautifying gives you structure. A source map gives you the original — names, comments, file boundaries and all — and it is worth checking whether one exists before settling for formatted output.
A source map is a JSON file recording how each position in the minified bundle corresponds to a position in the original source. Browsers use it transparently: with maps available, the debugger shows your real code, breakpoints land on the lines you wrote, and stack traces name real functions.
To find one, look for a comment at the end of the minified file: //# sourceMappingURL=bundle.js.map. If the file is published, requesting it gives you the complete original source, because maps embed the source content.
That has a security implication worth stating. Publishing source maps publishes your source. For open-source projects that is fine and helpful. For proprietary code it is an accidental disclosure, and it happens regularly — the build generates maps for debugging and the deploy ships them. The usual practice is to generate maps and upload them to an error-tracking service rather than serving them publicly.
Where no map exists, beautifying is the available option, and it recovers structure only.
Reading minified code without the original
When you are stuck with formatted-but-renamed code, a few techniques make it tractable.
Start from the strings. Minifiers rename variables and cannot touch string literals. An error message, a URL, a CSS class or an API endpoint is a fixed landmark, and searching for one takes you straight to the relevant function.
Follow the property names. Object properties accessed with dot notation are usually preserved, because renaming them would break any external consumer. a.getUserProfile tells you what a is even though its name is gone.
Identify the libraries. Bundles concatenate dependencies, and a recognisable chunk of a known library can be mentally skipped. Version strings and licence comments — which minifiers often preserve deliberately — help here.
Use the browser rather than the file. Chrome's "Pretty print" formats in place and, more usefully, lets you set breakpoints and inspect live values. Watching a hold a user object at runtime identifies it faster than any amount of reading.
Rename as you go in a local copy. Working out that n is the retry count and renaming it everywhere compounds — each identification makes the next easier.
Frequently asked questions
Is my code sent to a server?
No. Formatting happens entirely in your browser, which matters because the code you need to inspect often contains API endpoints, keys or unreleased logic.
Will formatting change what my code does?
No. Only whitespace between tokens changes. The contents of strings, template literals and regular expressions are preserved exactly.
Can it recover my original variable names?
No. Minifiers rename local variables to single letters and that mapping is not kept in the output. Use a source map if the build published one — that restores names, files and line numbers.
Why are the comments gone from my minified file?
Minification removes them from the file entirely. They are not hidden or compressed — there is nothing to restore.
Does this handle modern JavaScript?
Yes — arrow functions, classes, template literals, optional chaining, nullish coalescing and spread syntax are all tokenised correctly.