About the JavaScript Formatter
The JavaScript Formatter transforms compressed, minified or poorly indented JavaScript into clean, readable code. It is ideal for studying third-party scripts, debugging production bundles, reviewing code snippets from forums, and tidying up your own code.
The formatter supports modern JavaScript syntax including arrow functions, classes, template literals, async/await and modules, and it also works for JSON. Choose your preferred indentation. Note that formatting cannot restore original variable names that were shortened by a minifier, but it makes the logic far easier to follow.
Before and after: a real formatting example
Minified code from a website usually arrives as one long line. Here is a small piece of it:
function t(e){if(!e)return null;const n=e.split(",");return n.map(e=>e.trim()).filter(Boolean)}
After formatting with 2-space indentation it becomes:
function t(e) {
if (!e) return null;
const n = e.split(",");
return n.map(e => e.trim()).filter(Boolean)
}
The logic is the same, but now you can see at a glance that the function splits a string on commas, trims each part and drops empty values.
When it helps most
- Debugging a live site: paste a script from the browser's developer tools to find where an error is thrown.
- Reviewing copied snippets: code from forums or chat often loses its line breaks. Formatting makes it safe to read before you use it.
- Cleaning up your own code before you share it with a teammate or a teacher.
Tip: if the formatted result still looks strange, the original probably has a syntax error, such as a missing bracket. Fix that first, then format again.
How to use the JavaScript Formatter
- Paste your JavaScript into the input box.
- Choose 2 spaces, 4 spaces or tabs.
- Click Format JavaScript.
- Copy the beautified code.
Frequently asked questions
Can it recover original variable names?
No. Minifiers permanently rename variables, but formatting still restores readable structure and indentation.
Does it execute my code?
No. The code is only parsed as text for formatting and is never executed.
Does it support TypeScript?
Simple TypeScript usually formats correctly, but type-heavy syntax may not be handled perfectly.
