JavaScript Formatter
Format and beautify JavaScript code.
How to Use JavaScript Formatter
Paste your JavaScript into the input box, whether it is minified, partially obfuscated, or hand-mangled.
Set the indent width to 2 or 4 spaces and pick a brace style that matches your project.
Click the "Process" button to re-indent the code and place each statement on its own line.
Copy the beautified script, or download it and run it through your linter and tests before shipping.
Features
Frequently Asked Questions
Related Tools
JSON Formatter
Format and beautify JSON data with proper indentation.
JSON Validator
Validate JSON data and find syntax errors.
JSON Minifier
Minify JSON by removing whitespace and formatting.
HTML Formatter
Format and beautify HTML code.
HTML Minifier
Minify HTML code to reduce file size.
CSS Formatter
Format and beautify CSS code.
About JavaScript Formatter
Production JavaScript arrives minified, and a single line of 200,000 characters is not something you can debug. The JavaScript Formatter parses your code and re-prints it with proper indentation, putting every statement on its own line and every block brace on its own line so the control flow is visible again.
JavaScript has a few syntax traps that naive reformatters fall into. Regex literals versus division, template literals containing braces and expressions, and semicolon-free code all require real parsing rather than pattern matching. Those are handled here, so a line that looks like a broken regex is left intact and a nested template literal keeps its structure.
Comments are kept and indented alongside the code they document, which matters when you are trying to work out why a bundled function behaves differently from the source you wrote. Indent width and brace style are both configurable. This is a readability tool, not a compiler: it changes whitespace, never tokens, so behaviour is identical.
When to Use This Tool
- Reading a third-party or bundled script you need to understand quickly
- Reverse engineering a snippet from a browser script tag
- Formatting code for a tutorial, blog post, or Stack Overflow answer
- Comparing two builds of a script line by line
- Cleaning up code generated by a template or string concatenation helper