Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

JavaScript beautifier

Paste JavaScript or open a .js file and get readable code back: one statement per line, blocks indented, spaces around operators. Choose the indent and brace style, then copy or download; the code is formatted on your device.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Options
Beautified JavaScript

15 linesWhitespace only: names and logic unchanged

function total(items, tax) { let sum = 0; for (const i of items) { sum += i.price * i.qty } return Math.round(sum * (1 + tax) * 100) / 100 } const cart = [{ price: 4.5, qty: 2 }, { price: 12, qty: 1 }]; fetchRates().then(r => r.json()).then(d => show(total(cart, d.tax))).catch(() => show("\x4f\x66\x66\x6c\x69\x6e\x65"));
  • 2-space indent
  • Braces on the same line
  • Input looked minified (a 276-character line)
Size
276 B → 342 B
Lines
1 → 15
Longest line
276 → 119 characters
Deepest indent
2 levels

How to use the JavaScript Beautifier

  1. Paste the code into Your JavaScript, or pick one with Or choose a .js file; a chosen file is opened locally, not sent.
  2. Choose the Indent and where Braces go. Set Wrap long lines if lines still run off the screen.
  3. Tick Chained calls on separate lines for long promise or array chains, and Decode \xNN escapes in strings to read text hidden as hex codes.
  4. Press Copy or Download to take the formatted file.

How do I format minified JavaScript?

Paste it into the box and the formatted version appears at once: every statement starts a new line, each block inside braces moves one indent step right, and operators and commas get a space on each side. Copy it or download it as beautified.js. The code itself is the same; only the whitespace around it is new.

The example in the box is a single minified line of 276 characters (276 bytes): a function that totals a cart, an array of two items and a chain of promise calls. Formatted with 2 spaces it becomes 15 lines and 342 bytes, and the longest line drops to 119 characters. That remaining long line is the promise chain; tick Chained calls on separate lines and each .then() and .catch() gets its own line, which gives 18 lines with none longer than 53 characters.

The result panel shows the size, line count, longest line and deepest indent before and after, so you can see how much a file opened up. A chip says when the input looked minified, which is the case when almost everything sits on one or two very long lines.

Lines and bytes of the minified example, per option
SettingLinesSizeLongest line
2 spaces, braces on the same line (default)15342 bytes119 characters
4 spaces15362 bytes119 characters
Tab15332 bytes119 characters
Braces on their own line19345 bytes119 characters
Chained calls on separate lines18351 bytes53 characters
\xNN escapes decoded15321 bytes98 characters

Can you unminify JavaScript back to the original?

Only the layout comes back. A minifier removes comments, line breaks and spaces, and usually renames local variables and parameters to one or two letters. The beautifier restores readable spacing and line structure, but a parameter called e stays e, because the original name is no longer anywhere in the file.

The names can come back only from a source map. The source map format, standardised by Ecma International as ECMA-426, is a separate file that maps positions in the generated code back to the original sources and can carry a list of the original symbol names. Developer tools read it to show the real code while debugging. If a site publishes its source maps, they are a better starting point than any beautifier.

Obfuscated code is a harder case. Some scripts hide their strings as hexadecimal escapes such as \x4f\x66\x66. Tick Decode \xNN escapes in strings and printable ones are written as plain characters, so the example's hidden word reads "Offline". The value of the string does not change, only the way it is spelled. Code that builds itself at run time, or encrypts its own text, stays unreadable here: a formatter does not run the code.

Does beautifying change what the code does?

It should not, because it only adds or removes spaces, tabs and line breaks between the pieces of the code. It does not rename anything, reorder anything, or add semicolons: let a=1 on one line and let b=2 on the next come back as let a = 1 and let b = 2, still without semicolons. Text inside quotes and template literals is copied as written, extra spaces included.

It is also not a syntax checker. Broken code is indented as well as it can be and returned still broken, with no error message. If a file fails after formatting, the cause is almost always that it failed before too; run it or its tests to be sure. For production, keep the formatted file as your source and let your build step minify it again.

Paste only JavaScript here. A whole web page is better served by the HTML beautifier, which also formats the scripts and style blocks inside it, and JSON data reads best in the JSON formatter, which also validates it.

Which brace style and indent should I use?

Use whatever the project already uses; consistency matters more than the choice. "On the same line", the default here, puts the opening brace at the end of the line that starts the block: if (ok) { / save() / } else { / retry() / }. "On their own line" gives every brace a line of its own: if (ok) / { / save() / } / else / { / retry() / }, which adds lines but lines up each pair. "Same line, else and catch below" keeps opening braces on the same line but starts else, catch and finally on a fresh line: if (ok) { / save() / } / else { / retry() / }.

Large files work too. Up to 5 million characters can be formatted at once, which covers most single bundles. The result box shows the first 200,000 characters so the page stays quick, while Copy and Download always carry the whole file. Blank lines you left between functions on purpose are kept, never more than one in a row; untick Keep blank lines (up to one) to close every gap.

Two spaces keep deeply nested callbacks on screen, four spaces make each level easier to see, and a tab lets every reader set the width in their own editor, which also makes the file the smallest of the three. Wrapping at 80 or 120 characters breaks long argument lists and expressions so they fit narrow windows and side-by-side diffs.

Use it with

Questions

How do I beautify JavaScript online?

Paste the code into the box above; it is formatted as you paste. Choose the indent and brace style, then copy or download. The minified example goes from 1 line to 15.

Can I unminify JavaScript?

The spacing and line breaks, yes. Original variable names and comments, no: minifying removes them from the file. Only a source map published with the code can bring the names back.

Does beautifying JavaScript change how it runs?

No. Only whitespace between tokens changes; names, strings and logic stay the same, and no semicolons are added. Decoding \xNN escapes changes how a string is written, not its value.

Can it deobfuscate JavaScript?

Partly. It lays the code out and can decode hexadecimal string escapes, which reveals hidden text. It does not run the code, so anything built or decrypted at run time stays hidden.

Does it check my JavaScript for errors?

No. It formats what you paste, even if it is broken, and shows no syntax errors. Run the code or a linter to find mistakes.

Is my code uploaded anywhere?

No. js-beautify ships inside this page, so formatting happens locally and no request carries your script. Load the page, disconnect from the network, and it still formats.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.