go-supertools
Developer & Data Tools

JS Formatter

Format and indent JavaScript so it is easy to read.

Runs in your browser Your input never leaves your device.

About this tool

Paste JavaScript and the tool re-indents it and puts statements and blocks on separate lines using the js-beautify library, with a 2 or 4 space indent. It reformats whitespace only. It does not rename variables, add or remove semicolons, check your syntax or run your code, so a script with an error is still formatted as far as the tool can read it. Minified code becomes readable, but original variable names lost during minification do not come back. Everything runs in your browser and nothing you paste is uploaded.

How to use it

  1. Paste your JavaScript into the input box.
  2. Pick a 2 or 4 space indent.
  3. Read the formatted code in the output.
  4. Press Copy to use it.

Example

Existing semicolons are kept and missing ones are not added.

Input
function add(a,b){return a+b}const x=add(1,2);
Result
function add(a, b) {
  return a + b
}
const x = add(1, 2);

Common problems

Minified variable names are still a, b, c
Formatting cannot recover names that were removed when the code was minified.
Output looks broken after a syntax error
The formatter does not validate. Check for missing brackets or quotes in the source.
JSON or TypeScript input
Plain JavaScript is expected. JSON usually works; use the JSON Beautifier for it.