DEVELOPER PRECISION ENGINE

JS Formatter / Minifier

Format or minify JavaScript code — Minify's previously-confirmed CRITICAL bug is now fixed: it no longer merges adjacent operators into a different one, so subtracting a negative number (e.g. "1 - -1") minifies safely instead of crashing at runtime. Format remains safe but still doesn't add operator spacing or place braces on the same line — those are deliberately left as disclosed limitations rather than risking new correctness bugs from a fragile from-scratch tokenizer.

No JavaScript provided

How to Use This Tool

1

Paste your JavaScript code into the input textarea.

Paste your JavaScript code into the input textarea.

2

Click "Format" to beautify with proper indentation

this is safe and won't change your code's behavior, but note it places the opening brace on its own line below the function/block declaration, not the same-line style shown in this tool's own earlier example, and it does not add or normalize spacing around operators like + or =

Pro Tip

Before pasting an unfamiliar minified script into your project, run it through Format first and actually read it — minification is also the easiest way to smuggle obfuscated tracking or malicious code past a casual glance, and beautifying it removes that cover in seconds. Minify's output can now be trusted directly for adjacent-operator expressions, but testing minified output before shipping remains good general practice regardless of tool.

About This Tool

When to Use

  • Deobfuscating a minified third-party script to understand what a suspicious snippet actually does before running it
  • Formatting JavaScript pasted from a forum answer or AI chat before dropping it into a project's codebase.
  • Minifying a small standalone utility script before shipping it without setting up a full bundler pipeline, now with confidence that adjacent-operator expressions like subtracting a negative number won't be silently broken.

Key Details

A JavaScript formatter and minifier is meant to beautify compressed or inconsistently indented JS into readable code, or strip it down to a minified build for production. This tool's Format feature is...

Worked example

The old published example for this tool used the input function add(a,b){return a+b}, claiming it would format into function add(a, b) {\n return a + b;\n} — spaced parameters, brace on the function's own line, spaced operator. Feeding that same input into the actual `formatJs()` function tells a different story: the parameters stay unspaced (add(a,b)), the opening brace lands on its own separate line below the function signature instead of beside it, and return a+b keeps its unspaced operator — this remains accurate today. Separately, minifying let x = 1 - -1; now correctly produces let x=1- -1 (a single protective space between the two minus signs) instead of the previous let x=1--1, which threw a real error when executed; running the new output confirms x correctly evaluates to 2.

Interpreting your result

Formatted output that preserves your original operator spacing exactly, and places each opening brace on its own line, is working as currently designed — not a bug in your source code. For Minify, the output can now be trusted to be functionally identical to your source in every case, including expressions with adjacent + or - characters — the previously-confirmed crash risk there is fixed and verified by actual execution.

JS Formatter / Minifier FAQ

Is minified JavaScript from this tool guaranteed to behave exactly like the original?

Yes, now genuinely — this was previously a confirmed bug: the minifier collapsed whitespace around operators using a regex that didn't check what was on either side, so two adjacent operators separated only by whitespace could merge into a different one (let x = 1 - -1; minified to let x=1--1, which actually threw "Invalid left-hand side expression in postfix operation" when run, instead of evaluating to 2). That's fixed: the minifier now only strips whitespace between an operator and a plain identifier/literal; when both sides of a space are operator characters, it keeps exactly one space between them, which is enough to guarantee the two operators can never accidentally merge into a different token, while still stripping every other whitespace as aggressively as before.

What does the JavaScript formatter do, and does it change operator spacing or brace placement?

It takes JavaScript with inconsistent formatting and reformats it with proper indentation and each statement on its own line, which is genuinely safe and doesn't alter code behavior. Two things it does not do, despite earlier claims: it doesn't add or normalize spacing around operators (a+b in your source stays a+b in the output — only pre-existing spacing is preserved, not standardized), and it places each block's opening brace on its own line below the declaration rather than on the same line. Both remain deliberately unbuilt: doing either correctly for arbitrary JavaScript (distinguishing binary from unary operators, telling a regex literal from a division sign, handling arrow functions and optional chaining, etc.) requires a genuine JS tokenizer, and a half-built one risks introducing new correctness bugs into a formatter that currently never changes what your code does — the same caution that led to fixing Minify's bug precisely rather than rewriting the whole whitespace engine.

Is this a linter or just a formatter?

This is a formatter, not a linter. It reformats code for readability but doesn't enforce coding style rules or detect potential bugs. For linting, use tools like ESLint alongside this formatter.

How does minification differ from formatting?

Formatting adds whitespace and line breaks for readability, verified via testing to be safe. Minification removes whitespace, comments, and newlines to shrink the file — now genuinely, verifiably safe as well: the operator-merging bug that could previously change what minified code actually did is fixed, verified by actually executing the minified output for a range of adjacent-operator expressions and confirming it evaluates to the same result as the original.

What JavaScript syntax is supported?

The tokenizer correctly distinguishes string literals (single, double, and backtick-quoted, including escaped quote characters) from real code, and correctly skips both // and /* */ comments without treating comment-like text inside strings as a comment. It processes braces, semicolons, and general statements broadly across modern JS syntax. It does not perform any syntax validation, so code with genuine syntax errors will still produce some kind of output rather than a clear parse error.

Does the formatter preserve code comments?

Yes. Both single-line (// comment) and multi-line (/* comment */) JavaScript comments are preserved in Format's output — confirmed via code read, comments are only stripped during Minify, not Format. Inline documentation, TODO comments, and disabled code are retained exactly by Format.

Master Your Entire Toolkit

Access 500+ specialized calculators and tools designed for precision. No sign-up required, 100% free.

Built and reviewed by the Toolzip Team · Based on ECMAScript Language Specification