Code Formatters

JavaScript Formatter

Format modern JavaScript with Prettier, including classes, optional chaining, and async/await.

Press Ctrl / ⌘ + Enter to run
Read-only result

Format modern JavaScript with Prettier, including classes, optional chaining, and async/await.

What this tool does

JavaScript syntax includes regular literals, template strings, classes, destructuring, and automatic semicolon insertion, which cannot be followed by simple line breaks after ;, {, }. This page uses Prettier Babel and ESTree plug-ins for grammar parsing and unified formatting.

  • Supports const/let, arrow functions, async/await, template strings, destructuring, optional chaining, and classes.
  • No calls to eval, new Function, or script injection.
  • Syntax errors are reported by the parser and no code path is executed.

How to use it

  1. Paste the JavaScript source code.
  2. Select the indent width.
  3. Click "Format JavaScript."
  4. Fix syntax errors, or copy/download the results.

Common uses

  • Clean up compressed or garbled code snippets.
  • Unify formatting before code review.
  • Locate incomplete expressions with parsing errors.

JavaScript Formatter Features

Formatting modern JavaScript with Prettier, including classes, optional chaining, and async/await. It is suitable for daily development, debugging, data sorting and code optimization scenarios. The processing results can be directly viewed, copied or downloaded.

FAQ

Will the entered code be executed?

No. The code only goes into the parser and produces text output, the page does not use eval, new Function or dynamic script.

Are optional chains and template strings supported?

Support. This page loads Babel and ESTree plugins for modern JavaScript.

Why is a semicolon added after formatting?

Current output rules enable semicolons for consistency; this is a typesetting choice, not running input.

Back to Developer Tools