JavaScript Formatter
Beautify minified or messy JavaScript with consistent indentation and line breaks. Strings, template literals, regular expressions and comments are left untouched.
How to format JavaScript
Paste your JavaScript
Paste or type it into the box, or press Try an example.
Pick the indentation
Choose 2 spaces, 4 spaces or a tab.
Copy or download
Paste the tidy code back into your file.
Worked example
This is what JavaScript Formatter gives for its own sample values. Open the tool above and change anything to try your own.
JavaScript
import {readFile} from "fs/promises";const cache=new Map()
export async function load(path,{retries=3}={}){if(cache.has(path))return cache.get(path)
for(let i=0;i<retries;i++){try{const text=await readFile(path,"utf8");cache.set(path,text);return text}catch(err){if(i===retries-1)throw err}}}
// done- Indentation
- 2 spaces
Formatted JavaScript
import { readFile } from "fs/promises";
const cache = new Map()
export async function load(path, { retries = 3 } = {}) {
if (cache.has(path)) return cache.get(path)
for (let i = 0; i < retries; i++) {
try {
const text = await readFile(path, "utf8");
cache.set(path, text);
return text
} catch (err) {
if (i === retries - 1) throw err
}
}
}
...About JavaScript Formatter
Beautify minified or untidy JavaScript. It indents blocks, puts statements on their own lines, spaces operators and lays out switch statements. Strings, template literals, regular expressions and comments are never changed, and semicolons are neither added nor removed.
FAQs
Does it change what my code does?
No. Only spaces and line breaks change.
Does it work for TypeScript or JSX?
It handles most everyday syntax, but it is made for plain JavaScript, so check the result on complex TypeScript or JSX.
Can I make it small again?
Use JavaScript Minifier.