How to use it
This JavaScript beautifier turns a minified line or inconsistently indented script into readable code with one statement per line and two spaces per level. Braces open on the same line, operators get consistent spacing and object properties are listed one per line. Strings, template literals and regular expressions are never modified, and nothing you paste is executed: it is formatted as text, entirely in your browser.
How to use the JavaScript beautifier
- Paste the code you want to read, such as a minified bundle, an inline script or a single function.
- Run the formatter with "Run tool" or the Ctrl + Enter shortcut.
- Follow functions, conditions and loops through the indented output.
- Copy the result or download it and open it in your editor.
Formatting conventions
The output follows a common, widely used style. A short sample shows most of it:
| Input | Output |
|---|---|
if(cfg.retry>2){start()}else{stop()} | if (cfg.retry > 2) {, then start() indented, then } else {, stop() and } |
const cfg={api:"/v1",retry:3} | const cfg = {, then api: "/v1", and retry: 3 on their own lines, then }; |
for(let i=0;i<n;i++) | for (let i = 0; i < n; i++), header kept on one line |
try{a()}catch(e){b(e)} | try { ... } catch (e) { ... } |
[1,2,3].map(n=>n*2) | [1, 2, 3].map(n => n * 2), arrays and arguments stay inline |
Two habits of the formatter to know: method chains such as fetch(u).then(...).then(...) stay on one line, with only brace-delimited function bodies expanded, and statements under a case label sit at the same depth as the label rather than one level deeper.
Beautifying is not un-minifying
A bundler's output such as function cartTotal(n,t){let o=0;for(const a of n)o+=a.price*a.qty;return o*(1+t)} becomes a clear five-line function, but the parameters are still n and t and the accumulator is still o. Meaningful names removed during minification are gone from the file, and no formatter can recover them. If you need the original names, look for the project's source map or repository. What the beautifier gives you is structure: enough to follow the logic and locate the line that misbehaves.
What stays exactly as it was
- String and template contents, including the spaces in
`Total: ${a+b}`and the expression inside${}. - Regular expressions: the tokenizer tells a division sign from the start of a regex, so
/\s+/gsurvives intact. - Line breaks that ASI depends on:
let a = 1andlet b = 2stay on separate lines in semicolon-free code. Missing semicolons are not added. - Comments, although a trailing comment after a semicolon may move to its own line.
The beautifier does not validate syntax and does not wrap long lines at a fixed width.
Practical uses
- Auditing third-party scripts: before adding a chat widget, tag or embed to your site, read what it actually does and which endpoints it calls.
- Debugging production errors: search the formatted file for the function name in a stack trace and read the surrounding logic. Line and column numbers in the trace still refer to the minified file.
- Reviewing changes: format two versions with the same rules and compare them in the text diff checker.
- Learning: step through a compressed example to see how it is put together.
If what you pasted is JSON rather than JavaScript, the JSON formatter is the better fit, because it also validates the syntax and reports errors by position.
Privacy and related tools
Formatting happens in JavaScript in your own tab; the code is treated as text, never run, and not sent to the server. Only an anonymous usage counter is incremented. To shrink the code again for production, use the JavaScript minifier.