Skip to content
DoItJag

JavaScript Formatter

Make minified or untidy JavaScript readable, with your choice of indentation, semicolons and quote style.

or drop a file here · .js, .mjs, .txt · up to 20 MB

Options

About the JavaScript Formatter

Reading someone else’s script is hard enough without cramped loops, missing line breaks and indentation that changes from one function to the next. This formatter parses the code and prints it again in a consistent style with Prettier, the formatter many JavaScript projects use for every commit.

The code is only parsed, never run, so it is safe to paste a script you do not trust.

When to use it

  • You want to read the source of a bookmarklet, a snippet from a forum or a minified file.
  • A tag manager or CMS field mangled the layout of a script you pasted earlier.

Worked example

Choose Try an example to load a cart-total function written on two cramped lines, then press Format JavaScript with the defaults.

The function gets its body indented by two spaces, with the loop on its own lines and spaces around operators such as += and *. The cart array is spread so each product object sits on a separate line, and a trailing comma is added after the last one, which keeps future diffs small. The comment at the top stays in place.

Untick Semicolons and tick Single quotes, then format again: the statements lose their semicolons and the product names switch to single quotes, without any change in behaviour.

Options

  • Indentation: 2 spaces, 4 spaces or tabs.
  • Semicolons: when off, Prettier adds one only where leaving it out would change the meaning.
  • Single quotes: used where they do not need extra escaping.

Limits

  • Supported: modern JavaScript and JSX. TypeScript type annotations are reported as syntax errors.
  • Formatting minified code helps a lot, but short variable names chosen by a minifier and removed comments cannot be recovered.
  • A syntax error stops formatting and is shown with its line and column.
  • To shrink a script instead, use the JavaScript minifier. JSON data is better handled by the JSON formatter.

How to use JavaScript Formatter

  1. Paste JavaScript or open a .js file.
  2. Choose the indentation, line width, semicolons and quotes.
  3. Select Format JavaScript, check the result, then copy or download it.

Privacy: how it works

Everything happens in your browser. Your text is not sent to any server.

Frequently asked questions

Can it un-minify code?

It restores line breaks and indentation, which makes minified code much easier to read. It cannot bring back the original variable names or comments that a minifier removed.

Does it support TypeScript?

No, only JavaScript, including modern syntax and JSX. TypeScript type annotations are reported as errors.

Is my code run?

No. It is parsed and printed, never executed, and it stays in your browser.