How to use JavaScript Formatter
- Paste JavaScript or TypeScript (minified code works too).
- Choose indentation and how many blank lines to keep.
- Copy the formatted code from the output panel.
JavaScript Formatter features
- Re-indents minified or messy JavaScript and TypeScript
- Understands strings, template literals with nested ${}, regex literals and comments
- Normalises spacing around operators, keywords, braces and commas
- Handles switch/case, arrow functions, classes, generics and object literals
- Preserves your line breaks and semicolon style (ASI-safe — never changes behaviour)
- Keeps up to N blank lines; optional else/catch on a new line
JavaScript Formatter example
Expand a minified function
Input:
function sum(a,b){if(!a)return b;return a+b}Output:
function sum(a, b) {
if (!a) return b;
return a + b
}Frequently asked questions about JavaScript Formatter
Does it support TypeScript?
Yes. Type annotations, generics such as Map<string, number>, interfaces and decorators are formatted; the tokenizer is shared for JS and TS.
Will it add or remove semicolons?
No. The formatter preserves your line breaks and semicolon style so automatic semicolon insertion behaves exactly as before. It only reindents and normalises spacing.
Are regex literals, template strings and comments safe?
Yes. The tokenizer understands regex literals (including character classes), template literals with nested ${} expressions, and both comment styles, so their contents are never modified.
Can it format minified code?
Yes — that is the main use case. Minified one-line code is expanded into readable, indented statements. Renamed identifiers cannot be recovered, of course.
Does my code leave the browser?
No. Formatting is done locally in your browser.
Technical notes
This is a whitespace formatter, not a full parser: it never rewrites tokens, so it is safe on syntax it does not fully understand (JSX, decorators, newer proposals). Because JavaScript has automatic semicolon insertion, existing line breaks are preserved and only new ones are added after ; { and }.