How to use the JavaScript Formatter
- Paste JavaScript or TypeScript, or open a file.
- Choose the language and style options.
- Copy or download the formatted code.
Powered by Prettier
The formatter runs Prettier — the most widely used JavaScript formatter — directly in your browser. It supports modern syntax (ES2024+, JSX, TypeScript including generics and decorators) and prints code in a consistent, widely accepted style.
Reading minified code
Formatting a minified bundle restores line breaks and indentation, which makes it much easier to follow. Variable names shortened by a minifier can't be restored, though — that would require the source map.
The options
- Language — JavaScript / JSX or TypeScript / TSX. Choose TypeScript for type annotations, interfaces and generics, or they'll be reported as syntax errors.
- Line width — 80, 100 or 120 characters. Prettier wraps longer lines at this width; 80 is its default, and many teams choose 100 or 120 for wide screens.
- Semicolons — add a semicolon at the end of every statement, or only where JavaScript needs one to avoid ambiguity.
- Single quotes — use
'instead of"for strings, unless that would need more escaping.
When it's useful
Tidying a snippet from Stack Overflow or ChatGPT before pasting it into a project; reading a minified script to find out what it does; making a code sample consistent before putting it in documentation or a blog post; or formatting code on a machine where you can't install an editor plug-in. For JSON, CSS and HTML there are dedicated formatters with options suited to each language.
Private by design
Code is formatted locally; nothing is uploaded. Prettier is loaded only when you open this page, so other Expensico tools stay fast.
Frequently asked questions
Why are there so few options?
Prettier is intentionally opinionated: a small set of options keeps code consistent across teams. The most commonly changed ones are offered here.
Why does it report a syntax error?
Prettier must parse the code before it can print it, so it stops at real syntax errors such as a missing bracket. The message gives the line and column. TypeScript syntax in JavaScript mode also causes this — switch the language to TypeScript.
Can it minify JavaScript?
No. Minifying JavaScript safely requires a full minifier like Terser or esbuild, which belongs in your build process.
Is what I enter stored or sent anywhere?
No. Calculations and processing happen in your browser. Nothing you type is sent to our servers. Some tools remember your last input in this browser's local storage for convenience; you can clear it at any time.