Paste minified JavaScript and get it back readable, or go the other way and strip comments and whitespace. The important thing here is what the tool refuses to touch: it tokenises your code and regenerates only the whitespace between tokens, so strings, template literals, regular expressions and comments come out byte-identical. Formatters built on regular expressions eventually reach inside one of those and corrupt it, and because the result still looks like code the damage is easy to miss. Getting that right means resolving whether a slash starts a regex or is division — undecidable from the character alone, since `(a + b) / c` is division while `if (x) /re/.test(y)` is a regex — and counting brace depth inside template literals so a nested one does not end the outer literal early. Both are handled. Everything runs in your browser.
| Code | The trap |
|---|---|
| const r = /a\/b/g | A slash inside a regex |
| (a + b) / c | Division, not a regex |
| if (x) /re/.test(y) | A regex, despite following ) |
| `a ${`b ${c}`} d` | A template inside a template |
| "http://x.com" | // inside a string is not a comment |
| a - -b | Must not become a--b |
| return x | Must not become returnx |
No. It is tokenised and reformatted in your browser. Nothing is transmitted.
No. Only whitespace between tokens is regenerated; token contents are copied verbatim. That is the whole design, because formatters that rewrite with regular expressions do eventually mangle a string or a regex, and the result still looks like valid code.
From context, which is the only way. After an identifier or number it is division; after an operator, a keyword like `return`, or an opening bracket it is a regex. The hard case is a closing paren — `(a + b) / c` versus `if (x) /re/` — so it tracks whether each paren opened a control-flow header.
No, and it says so. It removes comments and whitespace only. Renaming variables, dropping dead code and rewriting expressions need a full parse and scope analysis, and a subtle error there gives you code that runs but behaves differently — much worse than a slightly larger file. Use a build-step minifier for production.
Partly. The tokenizer handles the syntax both share, so indentation is usually sensible. Type annotations and JSX have their own grammar, so results there are best-effort rather than guaranteed.
You can restore readable formatting, but not names or comments that a real minifier removed. Beautifying mangled code gives you structure back, not meaning.
The source is tokenised and only the whitespace BETWEEN tokens is regenerated — no token's contents are ever rewritten. That single constraint is what makes the tool safe, because a formatter built on regular expressions will eventually reach inside a string, a template literal or a regex and corrupt it silently. Tokenising JavaScript has one genuinely hard decision: whether a slash opens a regular expression or is a division operator. It is not decidable from the character, only from context. After an identifier or a number it is division; after an operator or an opening bracket it is a regex; after `return`, `typeof`, `case` and a handful of other keywords it is a regex. The awkward case is a closing parenthesis, where `(a + b) / c` is division but `if (x) /re/.test(y)` is a regex, so a small stack records whether each open paren began a control-flow header and the closing paren is judged accordingly. Template literals need their own care because they nest: an interpolation can contain another template literal, so the brace depth is counted rather than scanning to the next backtick, which would end the outer literal in the wrong place. Beautifying then indents on braces, breaks lines on statement semicolons but not on the ones inside a for-header, keeps `} else` and `} catch` on the closing brace line, and binds `++` and `--` to their operand in both prefix and postfix position. Minifying removes comments and whitespace and nothing else: no renaming, no dead-code removal, no expression rewriting. Those require a full parse and scope analysis, and a subtle mistake there yields code that still runs while behaving differently, which is far worse than a larger file. Where two tokens would merge if printed adjacent — `return x` becoming `returnx`, or `a - -b` becoming `a--b` — a single space is kept.