JavaScript validator — find syntax errors with line and column

Paste JavaScript and the validator parses it with the Babel parser, then points to the exact line and column of the first syntax error, or confirms the code is valid.

Live demo · real result from this tool

No syntax errors found.

StatusValid
Lines
8
Top-level statements
3
Functions
1
Type
Script

Processed on your device — nothing is uploaded.

How to use the JavaScript validator

  1. Paste your code into the JavaScript box.
  2. Read the result. Valid code shows No syntax errors found. with the number of lines, top-level statements and functions, and whether it is a script or an ES module.
  3. Invalid code shows the line and column of the problem and a Where the parser stopped frame with a caret under the spot.
  4. If the parser recovered from more than one problem, an All errors table lists each one.

What it does and when to use it

Use it when a build or a browser console says “Unexpected token” and you want to find the spot in a pasted snippet. It also helps to check a code sample before you put it in documentation, or to test code copied from an email or chat where quotes and brackets often get damaged.

The tool checks syntax only. Once the code is valid, the JavaScript formatter can tidy it and the JavaScript minifier can shrink it. If the error is about a name, the JS variable name validator explains which identifiers are allowed. To try the code and see its output, use the JS console simulator.

How it works

The page loads the Babel parser that ships with Prettier and builds a syntax tree from your text. Babel can recover from some mistakes and keep going, so the tool reports the first problem as the main error and lists any others in a table. Columns are counted from 1. When the code parses, the tool walks the tree to count functions (declarations, expressions, arrows and methods) and to look for import or export declarations.

Worked examples

Valid module.

function greet(name) {
  return `Hi, ${name}`;
}
export default greet;

Result: Status Valid, 4 lines, 2 top-level statements, 1 function, Type ES module.

A missing closing brace. const user = { name: 'Asha', roles: ['admin'] ; gives “Syntax error — line 1, column 47: Unexpected token, expected “,”“. The caret sits on the semicolon, where the parser expected a comma or }.

Several errors at once.

let x = 1;
let x = 2;
const y;

The main error is line 2, column 5: “Identifier ‘x’ has already been declared.” The All errors table adds line 3, column 8: “Missing initializer in const declaration.”

Limits and tips

  • Fix from the top. One missing bracket can cause errors further down. Fix the first error and check again.
  • An error at the last line often means an unclosed {, ( or string earlier in the file.
  • No TypeScript. Strip types or check .ts files with the TypeScript compiler.
  • Not a linter. Style issues and unused variables are not reported.

Frequently asked questions

Does it find runtime errors such as undefined variables?
No. It checks only whether the code can be parsed. A call to a function that does not exist, a typo in a property name or a wrong type will pass. Use a linter such as ESLint and run your tests for those.
Can I validate TypeScript?
No. Type annotations are a syntax error here: let n: number = 1; fails at line 1, column 6. JSX, on the other hand, is accepted.
Why is my code reported as valid when Node rejects it?
The parser is set up to be forgiving. A top-level return statement and import declarations anywhere in the file are accepted, even though a real script or module would reject them.
How does it decide between Script and ES module?
The tool reports ES module when it finds at least one import or export declaration, and Script otherwise. It does not read your package.json.
Is my code run or uploaded?
Neither. The parser is loaded into the page the first time you use it and reads the text in your browser. Your code is never executed.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close