tool

JavaScript Formatter, Validator & Minifier

Clean your JS code without the headache. Format messy code, find syntax errors, and make your JavaScript smaller and cleaner in seconds.

input
0 characters
1
result

paste your code and choose format or minify

Beautify, lint and minify JavaScript in your browser

Paste JavaScript from a minified file, a code review, Stack Overflow or an old project and turn it into something you can read. This tool formats code with Prettier, checks it with ESLint for syntax errors and common bugs, and can strip whitespace and comments to create a compact version. It supports modern syntax including ES modules, arrow functions, classes, async/await and optional chaining, and everything runs locally in your browser.

What can you do?

  1. 1. Format JavaScript
    Re-indent code with two spaces, add semicolons, normalise quotes and wrap long lines at about 100 characters, giving every snippet the same predictable style.
  2. 2. Validate and lint
    Catch syntax errors and likely bugs before you run the code: undefined variables, unreachable code, duplicate object keys or switch cases, == comparisons, eval() and more. The first problem is shown with its rule name, line and column.
  3. 3. Minify JavaScript
    Remove comments, line breaks and extra spaces to shrink a snippet for inline <script> tags, bookmarklets or quick embeds.
  4. 4. Count functions and lines
    See how many named functions and lines the code contains, a quick way to gauge the size of an unfamiliar script.

Why format and lint JavaScript before using it?

Reading minified or inconsistently formatted JavaScript is slow and error-prone. Formatting gives every block, callback and object its own indentation level, so the control flow is visible and mismatched braces jump out.

Linting goes a step further and flags code that is valid but probably wrong. A variable that was never declared, a duplicated key that silently overwrites an earlier one or a loose == comparison are all easy to miss when reading, and much cheaper to fix before the code reaches a browser.

How to format JavaScript online

  1. 1. Paste your code
    Paste a function, a module or a complete script into the editor.
  2. 2. Choose Format, Minify or Validate
    Each action validates the code first, so you always know whether the result is based on code that parses cleanly.
  3. 3. Resolve what the linter reports
    If an error or warning appears, fix it in the input, or tell the linter about it as explained below, then run the action again.
  4. 4. Copy the result
    Copy the formatted or minified code back into your editor.

What the JavaScript validator checks

Besides syntax errors, the validator runs a focused set of ESLint rules. Errors usually mean the code will fail at runtime; warnings point to patterns that are legal but risky.

ESLint rules used by the JavaScript validator
RuleLevelWhat it catches
no-undefErrorUsing a variable or global that was never declared
no-unreachableErrorCode after a return, throw, break or continue
no-dupe-keysErrorThe same key defined twice in an object literal
no-duplicate-caseErrorTwo identical case labels in a switch
no-func-assign / no-self-assignErrorReassigning a function declaration, or assigning a variable to itself
no-unexpected-multilineErrorLine breaks that make code parse differently than it looks
eqeqeqWarning== and != instead of === and !==
no-eval / no-implied-eval / no-new-funcWarningRunning strings as code
no-debuggerWarningLeftover debugger statements
no-constant-conditionWarningConditions that are always true or false

Fixing “is not defined” errors and warnings

The validator knows standard JavaScript built-ins plus common browser globals such as window, document, console, fetch, localStorage and the timer functions. Code that relies on Node.js globals (require, process), on a library loaded elsewhere on the page ($, gtag) or on less common browser APIs such as URL or alert is reported as using an undefined variable.

Because warnings are reported too, a snippet that uses == also needs attention before it can be formatted. You can handle both cases with standard ESLint comments at the top of your code, which the tool respects:

Example: declaring globals and disabling a rule

JSAdd these comments to the first lines of your input
/* global $, gtag */
/* eslint-disable eqeqeq */

const plan = document.querySelector("#plan").value;

if (plan == "pro") {
  gtag("event", "upgrade");
  $("#upgrade-banner").hide();
}

This minifier vs a build-tool minifier

The built-in minifier is deliberately simple. It is great for small snippets but is not a replacement for the minifier in your bundler.

Comparison of this tool's minifier with build tools like Terser and esbuild
This toolTerser / esbuild / SWC
Removes comments and whitespaceYesYes
Renames variables to shorter namesNoYes
Removes unused codeNoYes
Needs a build setupNo, paste and copyYes
Best forInline scripts, bookmarklets, snippetsProduction bundles

Tip: if your code leaves out semicolons, click Format first and then minify the formatted output. Formatting inserts the semicolons, so lines can't run into each other when line breaks are removed. Comment removal is pattern-based, so also double-check strings that contain // outside of a URL.

Frequently asked questions

Can I format TypeScript or JSX with this tool?

Not with this tool: its validator parses standard JavaScript, so TypeScript type annotations and JSX tags are reported as syntax errors. Use the TypeScript formatter for .ts and .tsx files and the JSX formatter for React components.

Why does it say a variable is not defined when my code works?

The variable is probably a global provided by Node.js, by the browser (such as URL or alert) or by a script loaded elsewhere on the page. Add a /* global name */ comment at the top of your input to declare it.

Can I un-minify or deobfuscate JavaScript?

Formatting restores indentation and line breaks to minified code, which makes it far easier to read. It can't restore original variable names or comments that a minifier has removed, and it doesn't reverse deliberate obfuscation.

Which code style does the formatter use?

Prettier's defaults with two-space indentation, a print width of 100 characters, semicolons and double quotes.

Is my code uploaded or stored?

No. Prettier and ESLint run inside your browser, so your code never leaves your device.

Debugging an API response or a pattern in your code? Try the JSON formatter or the regex tester.