Skip to content

JavaScript Formatter

Format and beautify JavaScript.

Loading…

About JavaScript Formatter

A snippet lifted from a bundle, a bookmarklet or a log is almost impossible to read until each statement has its own line. Paste it and press Format / Beautify: the code is re-indented with two spaces, opening braces stay on the same line, and statements are split across lines. Variable names stay as short as they were, because only whitespace changes, and the text is formatted without ever being run. Syntax errors are not reported, so broken code is laid out as far as it can be.

Features

  • Re-indents with two spaces and splits statements onto separate lines
  • Keeps opening braces on the same line
  • Quotes, names and semicolons are left as written
  • Handles arrow functions, async and await, classes and template literals
  • The code is only formatted as text and is never executed

Limitations

  • Only whitespace changes: minified variable names are not restored, removed comments do not come back, and missing semicolons are not added.
  • JSX comes out mangled, and TypeScript is not specifically supported, so use plain JavaScript.
  • The indent is fixed at two spaces, and syntax errors are not detected, because the Valid marker only means the formatter finished.

How it works

  1. Paste the JavaScript into the JavaScript Input panel.
  2. Select Format / Beautify.
  3. Read the Formatted JS panel.
  4. Use Copy Output to copy the code, or Clear All to start again.

Example input

function add(a,b){return a+b;}
const result=add(2,3);

Frequently asked questions