JavaScript Formatter
Make minified or messy JavaScript readable.
INPUT
CHARS: 0WORDS: 0LINES: 0
OUTPUT
CHARS: 0WORDS: 0LINES: 0
How the JavaScript Formatter works
The code is parsed and printed again using Prettier's rules: consistent indentation, line breaks at a sensible width, spacing around operators and tidy chained calls. JSX and modern syntax such as optional chaining and async functions are supported.
Choose two or four spaces or tabs, single or double quotes, and whether to add semicolons. If the code has a syntax error, the message shows the line and column so you can find it quickly.
JavaScript Formatter examples
Format compact JavaScript code
Input
function add(a,b){const res=a+b;return res>0?res:0;}Result
function add(a, b) { const res = a + b; return res > 0 ? res : 0; }
When it is useful
- •Reading a minified script copied from a production site.
- •Normalizing a code snippet before sharing it in an issue or answer.
- •Quickly checking whether a snippet parses.
- •Applying a consistent style to a one-off script without setting up a project.
Frequently Asked Questions
Can it restore variable names in minified code?
No. Formatting restores layout only. Names shortened by a minifier cannot be recovered.
Does it support TypeScript?
Use the TypeScript Formatter, which understands types, interfaces and generics.
Does the code leave my browser?
No. Formatting runs locally using a JavaScript build of the formatter.
Related tools
- TypeScript FormatterPaste TypeScript and get it formatted with consistent style.
- JSON Formatter and MinifierPaste JSON to validate it and print it neatly, or compress it to a single line.
- HTML Formatter, Minifier and BeautifierClean up markup, or squeeze it down for production.
- CSS FormatterPaste CSS and get tidy, consistently indented code, or a compact minified version.