Advertisement

JavaScript Formatter

Make minified JavaScript readable again. Paste compressed code and get clean indentation with sensible line breaks, while strings and comments stay intact.

JavaScript input

Formatted output

Advertisement

How the formatter works

The tool scans your code character by character, tracking strings, template literals and comments so their contents are never touched. Braces and brackets control indentation depth, semicolons and closing braces trigger line breaks, and redundant blank lines are collapsed. The result is readable code with the logic byte-for-byte identical.

Know the limits

This is a pragmatic beautifier for everyday code, not a full parser: exotic syntax like regex literals containing braces can occasionally indent oddly. Always diff the formatted output against the original and test before shipping. For bulletproof formatting of a large codebase, a tool like Prettier is the next step.

JavaScript Formatter FAQs

Will formatting change how my code runs?
No. Only whitespace and line breaks are adjusted; tokens, strings and comments are preserved exactly, so behavior is unchanged.
Can it handle modern syntax like arrow functions?
Yes for common cases. The scanner is syntax-agnostic about most modern features, though very exotic constructs may format imperfectly.
Does it work on TypeScript?
Mostly. Type annotations generally survive, but complex generics with braces can confuse the lightweight parser. Verify the output.
Why do regex literals sometimes break formatting?
A regex containing characters like { or / looks like code structure to a simple scanner. If output looks wrong, check regex literals first.
Is my code sent to a server?
No. Formatting happens entirely in your browser, keeping proprietary code private.
Advertisement