Skip to main content
Premier SEO Services

Developer tools

JavaScript Formatter

Turn minified or badly indented JavaScript into readable code with consistent indentation, one statement per line and your choice of brace style. The formatting runs in your browser.

  • Runs in your browser
  • Free, no sign-up
  • Unlimited use
  • Updated 30 September 2026

JavaScript Formatter

Paste your text — the result updates as you type

  • Formatting restores layout, not the original variable names or comments a minifier removed.
  • Not TypeScript- or JSX-aware: plain JavaScript formats reliably; for .ts and .tsx files use Prettier in your editor.

How to use the JavaScript formatter

  1. 1Paste your code into the JavaScript box, or press Example to load a minified sample.
  2. 2Choose Indent (2 spaces, 4 spaces or tabs), Braces and Wrap lines at. Tick Break chained methods for long .then() chains.
  3. 3Press Format JavaScript (or Ctrl + Enter). The result appears in Formatted JavaScript with the before and after line count.
  4. 4Press Copy or Download to save formatted.js.

Example

Input
function greet(name){if(!name){return"Hello, stranger"}return"Hello, "+name+"!"}
Output
function greet(name) {
  if (!name) {
    return "Hello, stranger"
  }
  return "Hello, " + name + "!"
}

Indent: 2 spaces, Braces: Same line. The formatter adds line breaks and spaces only; it doesn't add the missing semicolons.

Formatting options

OptionWhat it changes
Indent2 spaces (common in JavaScript projects), 4 spaces, or tabs
Braces{ on the same line as if/function (the usual JavaScript style), on a new line, or short blocks kept on one line
Wrap lines atBreaks long expressions near 80 or 120 characters; off by default
Blank linesKeeps up to one or two blank lines you already had, or removes them all
Break chained methodsPuts each .then(), .map() or jQuery call on its own line
Decode \x and \u escapesRewrites "\x48\x69" as "Hi", which helps when reading obfuscated scripts

The formatter only changes whitespace and line breaks (plus escapes, if you ask). It doesn't change quotes, add semicolons or rename anything.

Unminifying code

A minifier removes whitespace and comments and usually renames local variables to single letters. Formatting puts the structure back: one statement per line, nested blocks indented, operators spaced. What it can't restore is information that was deleted: comments, the original names of local variables (e stays e), and any code a compressor folded together, such as if statements turned into a ? b : c expressions.

If the site publishes source maps (a //# sourceMappingURL= comment at the end of the file), your browser's developer tools can show the original source, names included. That is the only reliable way to get them back.

Formatting vs linting

A formatter decides layout: indentation, line breaks, spaces. A linter such as ESLint checks meaning: unused variables, == where you meant ===, missing await. Formatting never fixes a bug, and a linter doesn't care about indentation unless you configure it to.

In a project, let one tool own formatting (Prettier is the common choice) and run it on save, so diffs only show real changes. This page is for code you don't control: a minified library, a snippet from a forum, a script inside an HTML page.

JSON and TypeScript

JSON is valid JavaScript syntax, so it formats here, but the JSON viewer is better for data: it validates against the JSON standard, points to the exact line of an error and shows a collapsible tree.

The beautifier works on JavaScript tokens rather than a full TypeScript parser. Simple type annotations usually come through unchanged, but generics, decorators and JSX can be laid out oddly. Format TypeScript and React files with Prettier or your editor's built-in formatter.

Is my text private?

This tool runs entirely in your browser. Your text is not uploaded to our servers.

Sources

Questions about the JavaScript formatter

Can it restore original variable names?

No. A minifier throws the original local names away, so no formatter can bring them back. Only a source map from the site's build has them.

Does formatting change how code runs?

No. Only whitespace and line breaks change, which JavaScript ignores. The one exception is the optional escape decoding, which writes the same string values in a different form.

Does it support TypeScript?

Partly. Plain type annotations usually format fine, but the formatter isn't TypeScript-aware, so use Prettier for .ts and .tsx files.

Is my code uploaded?

No. The formatter (js-beautify) is downloaded to your browser the first time you press Format and runs there.

Last updated 30 September 2026Maintained by Premier SEO Services

Report a problem