Beautify or minify JavaScript with 2-space, 4-space, or tab indentation. Shows byte savings percentage after minifying β copy the result with one click.
JavaScript and TypeScript codebases require uniform formatting to maintain maintainability, streamline Git version control diffs, and ensure consistent code style across engineering teams. Formatters parse source code into an Abstract Syntax Tree (AST) and pretty-print it according to strict formatting rules.
'string') or double quotes ("string"), applied consistently.| Formatting Rule | Inconsistent / Messy Code | Standardised Pretty-Printed Code |
|---|---|---|
| Trailing Commas | { a: 1, b: 2 } | <pre>{ |
| a: 1, | ||
| b: 2, | ||
| }</pre> | ||
| Arrow Function Parens | x => x * 2 | (x) => x * 2 |
| Bracket Spacing | {foo: 'bar'} | { foo: 'bar' } |
| Binary Operators | const sum=a+b; | const sum = a + b; |
Basic text search-and-replace often breaks JavaScript code by misinterpreting strings, regex literals, or template literals. Professional formatters (such as Prettier and Biome) parse code into an Abstract Syntax Tree (AST):
Node.js (Prettier API)
import * as prettier from 'prettier';
async function formatJS(code) {
return await prettier.format(code, {
parser: 'babel',
semi: true,
singleQuote: true,
trailingComma: 'all',
tabWidth: 2,
});
}
const messy = "const add=(a,b)=>{return a+b};";
formatJS(messy).then(console.log);
user?.profile?.settings ?? defaultConfig) cleanly across multiline configurations.package.json, .eslintrc, and GitHub Actions workflow files.This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.