Skip to content
Buy me a coffee
Minifiers / Beautifiers

JavaScript Beautifier / Formatter

Formats JavaScript files with the chosen indentation level and brace style: collapsed, expanded or expanded with new line.

0 characters · 0 lines
Option 2: Or upload your JavaScript file
Applies when "Preserve existing line breaks" is checked.
Ctrl + Enter

About the JavaScript beautifier

This tool takes minified, compressed or simply messy JavaScript and rewrites it with consistent indentation, one statement per line and a predictable placement of braces. It is the natural companion of the JavaScript minifier: minify for production, beautify to read, debug or review. The beautifier understands modern syntax (ES2015+ classes, arrow functions, template literals, async/await, modules, optional chaining, JSX-free TypeScript-like code) and never executes or uploads your code.

Note that beautifying restores the layout but not the names: variables mangled by a minifier (a, b, t…) keep their short names, since the original ones are lost.

Brace styles

Collapsed (the usual JavaScript style)

if (a) {
   b();
} else {
   c();
}

Expanded (Allman style)

if (a)
{
   b();
}
else
{
   c();
}

Expanded new line

if (a) {
   b();
}
else {
   c();
}

Keep as-is leaves each brace where you wrote it and only fixes the indentation.

Options

OptionEffect
Indentation levelSpaces (or a tab) added for every block, object literal or continued expression.
Preserve existing line breaksKeeps the blank lines you used to separate logical sections, up to the configured maximum in a row. Unchecked, blank lines are removed and only the structure decides where lines break.
Space before anonymous function parenthesesWrites function () instead of function().
Keep array indentationLeaves the indentation of multi-line array literals untouched, useful for hand-aligned matrices or lookup tables.
End with a newlineAdds a final line break, as required by many linters and POSIX tools.
Comma-first stylePuts the comma at the beginning of the next line in object literals, arrays and variable lists.

Example

const users=[{name:"Ada",age:36},{name:"Linus",age:54}];function adults(list){return list.filter(u=>u.age>=18).map(u=>u.name)}console.log(adults(users));

becomes:

const users = [{
   name: "Ada",
   age: 36
}, {
   name: "Linus",
   age: 54
}];

function adults(list) {
   return list.filter(u => u.age >= 18).map(u => u.name)
}
console.log(adults(users));