JavaScript Formatter
Clean, organize and beautify your JS code instantly
Turn a wall of compressed JavaScript into readable code
Minified bundles, code pasted from a chat window, or a script edited by five people with five different habits all share one problem: they are hard to read. The JavaScript Formatter re-indents and re-wraps your code according to settings you pick, then shows the original and the cleaned version next to each other so you can confirm nothing looks wrong.
Step by step
- Paste your script into Source Code, or use Sample to load a short one-line function.
- Set Indentation to 2, 4 or 8 spaces (4 is preselected).
- Choose a Brace Style: Collapse (K&R), Expand (Allman) or End Expand.
- Optionally set Quote Style and Semicolons, and tick Break Chained Methods or Comma First Style.
- Click Beautify & Format JavaScript. Use Copy or Download to save the result as script.js.
A stats bar under the result reports the size, line count and character count of the formatted code.
Options explained
- Brace Style decides whether the opening brace stays on the same line as the statement or moves to its own line.
- Quote Style can convert strings to single or double quotes. Leave it on Original if your code mixes quotes inside strings, because the conversion is a simple text replacement and can misfire on a string that contains the other quote type.
- Semicolons can add missing ones or strip them. Again this is pattern-based, so review the output before committing it, especially in code that relies on automatic semicolon insertion.
- Comma First places commas at the start of lines in lists and object literals, a style some teams use to make diffs cleaner.
When people reach for it
- Reading a minified third-party script while debugging a browser issue.
- Normalizing a snippet to your project's indentation before pasting it into a pull request.
- Cleaning up code copied from a tutorial or Stack Overflow answer.
- Making a one-off script legible before handing it to a colleague.
Good to know
Formatting changes whitespace and layout, not behavior, but the quote and semicolon rewrites are heavier-handed, so run your tests afterwards. Renamed variables in minified code stay renamed: the tool cannot restore original names. The work happens in your browser, and the formatter needs its beautifier library to have loaded; if the page could not load it, the code is returned unchanged.
Related Tools