JavaScript Formatter
Beautify minified or messy JavaScript: consistent indentation, one statement per line and your preferred brace style. Also works for JSON and most modern JS.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the JavaScript Formatter
- 1 Paste your JavaScript.
- 2 Pick the indentation and brace style.
- 3 Copy the formatted code or download it as a .js file.
About the JavaScript Formatter
Minified JavaScript from a website or a bundle is squeezed onto a few lines and almost impossible to follow. The formatter puts every statement on its own line, indents blocks consistently and adds spaces around operators, so you can read and debug the code.
Variable names shortened by a minifier (a, b, c…) can't be restored; for that you need the source map. Formatting does make the control flow, functions and objects visible again, which is often enough to understand what a script does.
The formatter uses js-beautify and handles modern syntax such as arrow functions, classes, template literals, async/await and modules. It only changes whitespace and line breaks, so the code behaves exactly the same. It doesn't check for errors; incomplete code is formatted as well as possible.
Frequently asked questions
Can I unminify JavaScript?
Yes, the formatter makes minified code readable again. Original names and comments removed by the minifier can't be recovered without a source map.
Does it support TypeScript or JSX?
Plain TypeScript and JSX often format acceptably, but the formatter is made for JavaScript. Use Prettier in your editor for TypeScript and JSX projects.
What is the brace style?
"Same line" puts the opening brace after the if or function (the most common JavaScript style); "new line" puts it on its own line; "end expanded" puts only else and catch on new lines.
Is formatting the same as Prettier?
The idea is the same, the details differ. Prettier makes more decisions for you (line length, quotes, semicolons); js-beautify only re-indents and re-spaces your code.