How to format JavaScript without running it

JavaScript formatting parses source and prints it consistently, making control flow and nesting easier to review without executing the program.

Open the JavaScript Formatter

What a JavaScript formatter changes

A formatter can normalize indentation, line breaks, quotes, semicolons, parentheses, and wrapping. Because it works from a parsed syntax tree, the output may look different while retaining the parsed program meaning.

Formatting does not fix incorrect logic, resolve imports, bundle packages, or make new syntax run in old browsers.

How to format JavaScript

  1. Paste JavaScript or open a UTF-8 source file.
  2. Choose two spaces, four spaces, or tabs.
  3. Select Format JavaScript.
  4. Correct any parser error before trying again.
  5. Review the diff, then copy or download the result.

The ToolPixels formatter uses Prettier with its Babel parser for JavaScript and JSX. It does not support TypeScript on this page, and submitted code is never run.

A formatting example

Input

const greet=(name)=>{if(name){return `Hello, ${name}`}}

Readable output

const greet = (name) => {
  if (name) {
    return `Hello, ${name}`;
  }
};

Formatting versus other build steps

ToolPurpose
FormatterConsistent source layout
LinterProject rules and likely mistakes
TranspilerConvert syntax for a target runtime
BundlerResolve and package modules

Review points after formatting

  • Check automatic semicolon insertion boundaries.
  • Confirm the parser matched JavaScript or JSX rather than TypeScript.
  • Run the project's tests and linter.
  • Avoid mixing a one-off format with repository-wide settings.
  • Keep generated or vendored files out of broad formatting changes when appropriate.

Use the browser tool

Format JavaScript or JSX locally with selectable indentation. The source is parsed as text and never executed.

Format JavaScript