Skip to content

JavaScript Formatter

To format JavaScript online, paste your script or snippet, pick JavaScript / JSX or TypeScript / TSX, and choose Pretty with 2-space, 4-space, or Tab indent — or Minify for a compact paste. Pretty reflows it with Prettier at an 80-character line width; Minify collapses the whitespace. Then press Copy. Invalid code shows a parse error beside the input, nothing runs, and nothing is uploaded.

Updated

Paste JavaScript and format it locally — pretty-print with 2-space, 4-space, or Tab indentation for reading and review, or minify with an honest whitespace collapse. Closing the tab drops the workspace; we do not write it to localStorage or send it to a formatter API. This page is a JavaScript formatter / JS beautifier — and a TypeScript formatter — for text you already have, not a bundler and not a TypeScript type-checker.

Formatting runs in the browser with Prettier standalone: the babel parser for JavaScript and JSX, or Prettier's typescript parser for TypeScript and TSX (loaded only when you pick TypeScript). If the text cannot be parsed, the page shows an error next to the input instead of guessing at a fix. Identifiers and literals are preserved as written; this page reflows whitespace and indentation, it does not rewrite your logic, tree-shake, or minify with terser.

JavaScript workspace

JavaScript · Pretty

Applies in Pretty mode. Minify ignores indent and collapses whitespace.

Paste JavaScript or JSX. For interfaces, enums, or other TypeScript syntax choose TypeScript. Whitespace and indentation only — code is not executed, bundled, or type-checked. Nothing is uploaded.

Output

Whitespace formatter only — not terser/uglify, not a bundler, and not a TypeScript compiler or type-checker (type errors are not reported). Closing the tab drops the workspace. For HTML pages with inline scripts, HTML Minifier keeps <script> bodies safe.

How does the JavaScript Formatter work?

  1. 1. Paste JavaScript

    Drop in a script or snippet and pick JavaScript / JSX or TypeScript / TSX. Load example fills a tiny fictional snippet in the chosen language.

  2. 2. Format locally

    The browser runs Prettier in this tab — the babel parser for JavaScript/JSX, or the typescript parser for interfaces, types, enums, generics, and TSX. Nothing is uploaded and your imports are never fetched or executed.

  3. 3. Pretty-print or minify

    Choose Pretty with 2-space, 4-space, or Tab indent for reading and review, or Minify for a compact whitespace-collapsed form for pasting into a tight field. Logic stays as written; only whitespace and indentation change. Minify is not terser/uglify.

  4. 4. Copy the result

    Copy the formatted JavaScript. Closing the tab drops the workspace. Need HTML, CSS, XML, SQL, or JSON instead? Use the other Developer formatters on this hub.

Questions about JavaScript Formatter

What does this JavaScript formatter do?
It pretty-prints (beautifies) or minifies JavaScript in your browser. Paste a script or snippet, and it reformats whitespace and indentation so code is easy to read — or collapses whitespace for a compact paste. Switch to TypeScript / TSX to format .ts and .tsx code. It is a local JavaScript and TypeScript formatter, not a bundler and not a type-checker.
Does it upload my JavaScript?
No. Formatting runs entirely in this tab with Prettier standalone. There is no account, no server-side formatter, and no file upload. The text you paste stays here until you clear it or close the page. We do not write it to localStorage. That is the same privacy rule as HTML Formatter, CSS Formatter, XML Formatter, SQL Formatter, and JSON Formatter on this hub.
Why is there no /js-beautifier/ or /js-formatter/ second URL?
One canonical URL: /developer/javascript-formatter/. The page name matches the Developer formatter family. Queries like "js formatter", "format javascript", and "javascript beautifier" can land here; we do not publish a second /js-beautifier/ stub slug.
What happens if my JavaScript is invalid?
You get a short Prettier parse error next to the input and the output stays empty. The page does not invent missing braces or semicolons. Fix the script in an editor and paste again.
How is this different from HTML Formatter or CSS Formatter on this hub?
HTML Formatter formats HTML markup. CSS Formatter formats stylesheets. This page formats JavaScript and TypeScript with Prettier's babel and typescript parsers. They share the same privacy rule (local only) but accept different languages — they do not convert between JS, HTML, and CSS.
Does Minify use terser or uglify?
No. Pretty mode is Prettier with 2-space (default), 4-space, or Tab indent. Minify is an honest whitespace collapse after a successful Prettier parse — not terser, not uglify-js, and not a claim of production-grade compression. For advanced minify (dead-code elimination, mangling), use a local bundler.
Can it format TypeScript or JSX?
Yes. JSX formats in JavaScript / JSX mode (babel parser). For TypeScript, choose TypeScript / TSX: Prettier's typescript parser formats interfaces, type aliases, enums, generics, as and satisfies casts, access modifiers, decorators, and TSX components. If JavaScript mode fails on code that looks like TypeScript, the error tells you to switch. Formatting is not type-checking — type errors are not reported, nothing is compiled to JavaScript, and Minify still only collapses whitespace.
Can I change the indent width?
Yes. In Pretty mode, choose 2 spaces, 4 spaces, or Tab. The default is 2 spaces, matching Prettier's usual tabWidth. The choice works in both JavaScript / JSX and TypeScript / TSX modes. Minify ignores indent and collapses the whitespace.
Does it execute my code or fetch modules?
No. The formatter never runs your script, never evaluates expressions, and never fetches import or require targets. It only reflows whitespace and indentation in this tab with Prettier. Closing the tab drops the paste — there is no sandbox runner and no remote module fetch.

These tools run in your browser. Page Utils does not store, upload, or write to localStorage the keys, tokens, or text you paste. Results are a convenience aid, not legal, tax, or security advice.