JavaScript Formatter & Minifier

JavaScript Formatter & Minifier
Copied!
Input: 0 chars Output: 0 chars Saved: 0%

A client-side JavaScript formatter and minifier. Beautify mode adds proper indentation based on braces, brackets, and semicolons. Minify mode strips all comments and unnecessary whitespace. Shows input/output sizes and savings percentage.

Why Use This JS Formatter?

  • Two modes — Format for debugging or Minify for production.
  • String-aware — preserves content inside quotes and template literals.
  • Comment handling — format preserves comments, minify strips them.
  • Size savings — shows exact character count reduction.

Key Features

  • Brace-Based Indentation: Tracks {, [, ( nesting with 2-space tabs.
  • String Safety: Detects ", ', and backtick strings to avoid false reformatting.
  • Comment Types: Handles both // line comments and /* */ block comments.
  • One-Click Copy: Copy the formatted or minified result to clipboard.

How it Works

The formatter walks the code character by character, tracking string state (single/double/template quotes). Opening braces increase indent, closing braces decrease it. Semicolons and commas trigger line breaks. The minifier uses regex to strip both comment styles and collapse whitespace.

Try the JS Formatter

Paste JavaScript code, click “Format” or “Minify”, then copy the optimized result.