JavaScript Formatter
Re-indent your JavaScript one statement per line
Input
Output
Paste your input on the left and the result shows up here.
Or drop a file on this box, , or .
What is JavaScript Formatter?
You open a vendor script to find out why a checkout button misbehaves and get 40 KB of JavaScript on a single line. This page reflows it. Every { opens a new indented level of two spaces, a semicolon that ends a statement starts a fresh line (the two inside a for (;;) header stay put), and commas get a space after them, so the function boundaries and nested objects become visible again. Comments, strings, template literals and regex literals are copied through untouched, and any line break you already had is kept, because in JavaScript a line break can end a statement.
The one rule it never breaks: only whitespace changes. It will not put a line break after return, throw, break or continue, since automatic semicolon insertion would end the statement right there and your function would return undefined.
The reflow is a small tokenizer written in TypeScript and run by this tab, so proprietary client code you were handed for debugging stays on your machine. It does not parse or execute anything, which also means it will happily reflow code that would fail in Node.js; checking syntax is a separate job.
How to Use the JavaScript Formatter
The output panel rewrites itself on every keystroke in the input, so there is no Format button. Paste, read, and then decide whether you want the pretty version or the compact one.
Paste, Upload, or Load Sample
Drop the one-line script into the left Input panel, or use Upload for a .js file you saved from the network tab. Sample loads a short minified loop that totals data usage. Something like this is a typical starting point:
const readings=[{sensor:"greenhouse-3",celsius:21.4},{sensor:"greenhouse-4",celsius:23.9}];function average(list){return list.reduce((s,r)=>s+r.celsius,0)/list.length;}console.log("Avg:",average(readings)); The formatter does not check syntax. Broken code is reflowed as best it can, so run it through the validator if something looks off.
View Formatted Output
The right Output panel updates as you type. For the readings example, each object in the array gets its own block, function average(list) { starts a new line, and its return list.reduce((s, r)=>s+r.celsius, 0)/list.length; sits one level in. Spacing inside an expression is left the way you wrote it.
Copy, Download, or Minify
The reflowed code goes out through Copy, or as a formatted.js file through Download. Minify goes the other way and squeezes the input back down by stripping comments and whitespace, keeping the line breaks a missing semicolon depends on; it is a quick squeeze, not a Terser replacement. Clear empties the input when you move on to the next file.
When You'd Actually Use This
Code Review
A teammate pastes a bundled snippet into a pull request comment and asks if it looks right. Reflow it here and you can point at the exact nested callback you mean instead of "somewhere around column 3,000".
Debugging
Trying to debug minified production code? Format it first to make it readable. Much easier to set breakpoints and understand what's happening when the code is properly formatted.
Learning JavaScript
Curious how a library you use is built? Reflow its minified build and you can trace how one function hands an object to the next, which teaches more about real-world JavaScript than a toy example does.
Legacy Code Maintenance
Working with old, unformatted code? Format it to make it maintainable. Proper indentation and spacing make it way easier to understand and modify.
Common Questions
Is my code stored?
No. The tokenizer is JavaScript shipped with the page, and this formatter has no Share button or backend call, so there is nothing that could send or keep your script.
What JavaScript versions are supported?
We support all modern JavaScript syntax – ES5, ES6+, async/await, arrow functions, classes, modules, you name it. If it's valid JavaScript, we can format it. Check out the ECMAScript for more details.
Can I format invalid JavaScript?
It will reflow it anyway, because nothing here parses the code. An unclosed brace or quote throws off the indentation from that point on, so fix syntax errors first for a clean result.
What indentation does it use?
Two spaces per level. A { block always gets its own level; a ( or [ only does when you broke the line right after it, so a callback inside a call is not indented twice.
How big can my file be?
There is no hard cap. The formatter walks the text once and runs again on every edit, so a typical bundle of a few hundred KB is fine. For a multi-megabyte build, upload the file rather than typing into it, because each keystroke repeats the whole pass.
Can I customize the formatting?
Currently, we use standard formatting conventions. If you need specific formatting options, consider using command-line tools like Prettier for advanced customization.
Other JavaScript Tools You Might Need
Reflowing only changes whitespace. When the code also needs its escaped strings decoded, its syntax checked, or a shrink before it ships, these pages take over: