Skip to content
Categories
JavaScript Formatter
Format JavaScript to make it easier to read.
Overview
- Formats JavaScript packed into a single line into a readable form, using Prettier.
- Uses the Babel parser, so it handles modern syntax (arrow functions, destructuring, spread syntax, etc.) as well as code containing JSX.
- Useful for making minified code, or code with broken indentation copied from elsewhere, readable again.
Usage
- Enter the JavaScript you want to format into the text area.
- Click the "Format" button.
- The result, formatted according to Prettier's rules, is displayed below. Use the "Copy" button to copy it to the clipboard.
Example
Input
function add(a,b){return a+b}Output
function add(a, b) {
return a + b;
}Use Cases
- Formatting minified JavaScript into a readable form for debugging
- Unifying the indentation of code copied from elsewhere to match your project's style
- Formatting a code snippet into a consistent style before including it in a code review
FAQ
Is the JavaScript I enter sent anywhere?
No. Formatting runs entirely in your browser using Prettier; nothing is sent to an external server.
What happens if there is a syntax error?
An error message "The JavaScript syntax is invalid." is displayed along with details.
Does it support JSX?
Yes. Since it uses the Babel parser, code containing JSX syntax can also be formatted.
Notes
- Formatting fails if the JavaScript is syntactically invalid.
- Detailed style choices, such as adding semicolons or unifying quote style, follow Prettier's standard rules and cannot be customized individually.
- Formatting very large code may make browser processing slow.
Related Tools
Format TypeScript to make it easier to read.
Format HTML to make it easier to read.
Format CSS to make it easier to read.