# JavaScript Formatter

Paste minified or messy JavaScript and get it back indented and readable, with your choice of spaces or tabs. Free, in your browser.

Use it at https://lobsite.com/tools/js-formatter

## How to use it

1. Paste your JavaScript, open a `.js` file, or start from the sample: minified code.
2. Choose 2 spaces, 4 spaces or tabs. The formatted code appears as you type.
3. Copy it or download it as `script.js`.

## What it does

Statements go on their own lines, blocks are indented, and spacing around operators and after keywords is made consistent. The code does exactly the same thing: only whitespace changes. Formatting can't bring back names a minifier shortened, like `n` and `t`, or the comments it removed.

## When it helps

- Reading a minified script to see what it does, or to find where an error comes from.
- Tidying code from a snippet, an answer or an AI assistant before you edit it.
- Making two versions comparable before a diff.

## Frequently asked questions

### Does it work with modern JavaScript?

Yes: arrow functions, classes, template literals, async/await, optional chaining and modules all format.

### Does it check my code for errors?

No. It indents what's there, even if it wouldn't run. The [JavaScript Minifier](https://lobsite.com/tools/js-minifier) does parse the code, and reports the line and column of a syntax error.

### What about TypeScript or JSX?

Most TypeScript formats fine, since it's JavaScript with type annotations. For JSX and large projects, use Prettier in your editor.

### Is my code uploaded?

No. Formatting runs in your browser.

