JavaScript beautifier
Paste JavaScript to arrange its whitespace, blocks and statements.
Result
Formatted JavaScript
function greet(name) {
const message = "Hello, " + name;
return message;
}How it is calculated
- Strings, comments and regular expressions are kept together.
- Blocks and statements are reindented with two spaces.
- Formatting runs locally in your browser.
Example
function greet(name){const message="Hello, "+name;return message;}
Good to know
- The formatter improves layout but does not compile or validate JavaScript.
- Some complex styles may need manual adjustment.
When to use it
- Read a minified script to understand what it does.
- Format code copied from a page or a console before reviewing it.
- To test a pattern found in that code, use the Regular expression tester.
Frequently asked questions
Can formatting restore the original names?
No. Minifiers often rename variables to single letters; formatting only restores spacing. A source map, when published, can give the original code.
Does formatting change how the code runs?
It should not, as only spaces and line breaks change. Check with care where a line break could change meaning, such as after return.
Is it safe to run code I do not know?
Formatting it is safe, as the code is not executed. Do not run unknown scripts in your browser console.