Skip to content
ToolkitHub

JavaScript Formatter / Minifier

Format or minify JavaScript

Guide

Making JavaScript readable again

By Logappradeep · ServiceNow developer

JavaScript reaches you in many unreadable shapes: a bundled file from production, a bookmarklet, a snippet in an analytics tag, or code pasted into a chat that lost all its line breaks. This tool gives you a quick way to spread that code out so you can read it, and a quick way to squeeze a small script down when you need to inline it somewhere.

How the beautifier works

The formatter uses simple text rules rather than a full parser. It starts a new indented line after every opening brace {, ends a line after every semicolon, and puts each closing brace } on its own line. For example:

function add(a,b){const s=a+b;return s;}

is expanded so the function body, the const declaration and the return statement each sit on their own line. This is ideal for getting a first look at what a compressed snippet does. It is not a replacement for a parser-based formatter such as Prettier, which understands the full grammar and produces consistent, style-guide-compliant output.

How the minifier works

The Minify button removes /* block */ and // line comments, collapses whitespace, and removes spaces around operators and punctuation like =, +, (, ), , and ;. Real minifiers such as Terser or esbuild go much further: they rename local variables to single letters, remove dead code and rewrite expressions. Use those in your build; use this tool for small, quick jobs.

Where it helps

  • Reading a third-party tracking or embed snippet before adding it to your site.
  • Expanding a minified function from a stack trace to understand what it does.
  • Compacting a short script for a bookmarklet or an HTML attribute.
  • Cleaning up a code sample before pasting it into documentation.

Pitfalls developers hit

Text-based rules cannot tell code from data. Semicolons and braces inside strings, template literals, regular expressions or for (let i = 0; i < n; i++) headers will also trigger line breaks, so the formatted view is for reading, not for committing. Minifying has a sharper risk: code that relies on automatic semicolon insertion (no semicolons at line ends) can change meaning or break when its newlines are collapsed. A URL inside a string such as "https://..." is protected from comment stripping only in simple cases, so test minified output before you ship it.

Source maps exist because minified code is hard to debug. If you are investigating a production error, the original source or the source map is always a better starting point than reformatted output.

The tool works the same for plain TypeScript snippets, since the rules only look at punctuation. Your code never leaves the browser, and the last input is kept in local storage for convenience.

Frequently asked questions

Is this the same as Prettier?

No. This tool uses lightweight text rules for quick reading and compacting. Prettier parses the code and applies a full, consistent style, so use it for code you commit.

Can the minifier break my code?

It can if the code depends on automatic semicolon insertion or has unusual strings and regular expressions. Always run minified output before shipping it.

Does it rename variables like Terser does?

No. It only removes comments and whitespace. Variable mangling and dead-code removal require a full minifier in your build pipeline.

Why are there line breaks inside my for loop?

The beautifier breaks after every semicolon, including the two inside a for-loop header. That is expected with text-based formatting and does not affect the original code.