Format Code Now
/
Web & markupJavaScript Validator Next: Lua Minifier ›

JavaScript Validator

WM-94

Paste JavaScript and find out whether it parses. If not, you get the first syntax error with its line and column.

Runs in your browser. Nothing is uploaded.

JavaScript

Result

How to use it

  1. Paste your JavaScript, or open a .js file or drop it on the input box.
  2. Leave the parser on Babel, or choose Acorn for standard JavaScript only.
  3. Press Validate.
  4. If there is an error, use Go to error to jump to it.

What a pass means

The code is parsed with the Babel parser, or with Acorn if you choose it, and nothing is run. Both accept JSX, and only Babel accepts decorators. A pass means every token is in a place the grammar allows. Modules with import and export work, as do classes, async functions, optional chaining and template literals. A top-level return or await also passes, which a plain browser script would reject.

What it cannot find

Syntax is the only thing checked. An undefined variable, a call on the wrong type, an unreachable branch or a wrong import path all pass. For those, use a linter or run the tests. Type syntax from TypeScript or Flow is not valid JavaScript and is reported as an error.

Reading an error

The parser stops at the first problem, so later mistakes show up only after you fix it. The message gives a line and column, and Go to error moves the cursor there. The spot shown is where the parser got confused, which can be a line after the real cause, for example a missing bracket.

Error messages and what to do

MessageWhat it meansFix
Invalid JavaScript: Unexpected token, expected "," at line 2, column 9.The parser found a token it did not expect, here a missing comma or closing bracket.Check the line and the one before it for a missing bracket, comma or parenthesis.
Paste some JavaScript to check.The input box is empty.Paste or open some code first.

Questions people ask

How do I check JavaScript syntax online?

Paste the code and press Validate. A valid file shows a green message; an invalid one shows the first error with its line and column.

Does it run my code?

No. It only parses it, so nothing executes and nothing can have side effects. No. It only parses the text, so nothing executes and nothing can have side effects. That makes it safe to check code you do not trust yet.

Why does Babel accept code that Acorn rejects?

Babel supports proposals that are not part of standard JavaScript yet, such as decorators on classes. Acorn follows the standard more closely and stops at them. Pick Acorn to check that code is plain standard JavaScript, and Babel for code that uses newer syntax.

Will it catch undefined variables?

No. That needs a linter such as ESLint. This tool checks grammar only. No. Finding undefined variables needs a linter such as ESLint. This tool checks the grammar only, so it can say the code parses but not that it works.

Can it check JSON?

A bare JSON object is not a valid JavaScript statement on its own, because braces read as a block. Use a JSON validator for JSON files.

About this tool

Parses your code with the Babel parser, or with Acorn if you choose it, and reports the first syntax error with its line and column. Both accept JSX; Babel also accepts decorators, and Acorn does not. It checks syntax only: it does not run the code, find undefined variables, or check types. Module code with import and export is accepted, and so are a top-level return and await, which a browser script would reject. Code is parsed as it stands, so it cannot tell you whether it works. TypeScript and Flow annotations are not valid here.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.