Saved

Press the star next to a tool's name to save it.

All my tools

JavaScript Validator

This JavaScript validator checks code for syntax errors against the latest JavaScript, shows the line and column of any problem, and summarizes valid code.

Restored your last values ·

Automatic tries the code as a module first, then as a classic script. The code is only read, never run.

Your code is checked in your browser. It isn't run or uploaded.

Result

–

Paste JavaScript and press Validate.

Recent results

A JavaScript validator checks your code for syntax errors without running it. Paste JavaScript and this JavaScript validator parses it against the latest version of the language, then either confirms there are no syntax errors, with a short summary of the code, or points to the line and column of the first problem with a plain explanation and the surrounding lines. It handles modern syntax such as classes, arrow functions, async/await, optional chaining and import/export.

What a syntax error is

In JavaScript, a SyntaxError represents an error when trying to interpret syntactically invalid code. It's thrown when the engine finds tokens, or an order of tokens, that doesn't fit the grammar of the language while it's parsing the code. Because parsing happens before any code runs, a single syntax error stops a whole script from running at all. Common causes are a missing bracket or brace, a missing comma between items, an unclosed string, a stray character, or a keyword used where it isn't allowed.

What this validator checks

  • Syntax only. It reads the code the way a JavaScript engine does before running it, and reports anything that isn't valid JavaScript.
  • Latest JavaScript. Modern features are understood, so new syntax isn't flagged as an error.
  • Modules and scripts. Code with import and export is a module; older code that isn't may be a classic script. Automatic mode tries both.
  • A summary of valid code: the number of lines, top-level statements, functions, classes and imports.

It doesn't check for runtime errors, such as calling something that isn't a function, or for style problems. Valid syntax doesn't mean the code does what you want.

How to use the JavaScript validator

  1. Paste your code into the box.
  2. Choose how to check it, or leave it on Automatic.
  3. Press Validate.
  4. If there's an error, go to the line and column shown. The lines around it are displayed with a caret under the spot.
  5. Fix it and validate again; later errors only show once earlier ones are fixed.

Example

This code is missing a closing parenthesis:

const total = items.reduce((sum, x) => sum + x.price, 0;

The validator reports a problem on line 1 near the semicolon, where the parser expected a ) to close the reduce call. Adding the bracket, so the line ends with 0);, makes it valid.

Module or script?

JavaScript can be loaded as a module or as a classic script, and a few rules differ. Modules allow import and export statements and await at the top level, and always use strict mode, so some older patterns aren't allowed. Classic scripts allow those older patterns but not import or export. If your code works in one place and fails here, try the other mode to match how your page or tool loads it.

Reading error messages

  • Unexpected token means the parser found something it didn't expect at that point, often because something before it is missing.
  • Unterminated string constant means a quote wasn't closed.
  • Unexpected keyword usually means a reserved word is used as a name, or import is used in a classic script.
  • The line and column show where the parser noticed the problem; the actual mistake is often just before it.

Is it private?

Yes. Your code is parsed in your browser and never run or uploaded, so it's safe to check code you can't share.

Common syntax errors and fixes

  • Missing closing bracket or brace. Every ( needs a ), every [ a ] and every { a }. Count them in the lines around the error, or let your editor highlight matching pairs.
  • Missing comma between items in an array or object, such as [1 2] instead of [1, 2].
  • Unclosed strings. A string started with a quote must end with the same kind of quote on the same line, unless it uses backticks.
  • Extra comma or semicolon in the wrong place, such as a semicolon inside an object literal.
  • Reserved words as names. Words such as class, new or delete can't be used as variable names.
  • await outside async. In a classic script, await can only be used inside an async function.

Where the error is reported

The parser reads the code from top to bottom and stops at the first point where the code can no longer make sense. That point is often just after the real mistake. For example, a missing closing brace at the end of a function may only be noticed several lines later, when the next function starts. If the reported line looks fine, look a little earlier for an unclosed bracket, quote or comment.

Validating large files

The validator handles files of up to 2,000,000 characters in your browser. Because only the first syntax error is reported, fix errors one at a time from the top: correcting one can make several later "errors" disappear, because they were really side effects of the first.

Minified and bundled code

Minified code, where a whole program sits on one or two very long lines, can be validated too, but the column number will be large and harder to find by eye. Format the code with a JavaScript beautifier first, then validate it, so the error lands on a short, readable line.

Common mistakes

  • Pasting HTML with script tags; paste only the JavaScript inside them.
  • Pasting JSON with comments, or TypeScript types, which aren't plain JavaScript.
  • Looking only at the reported line. Check the line before it too.
  • Mixing modules and scripts. Choose the mode that matches how the code is loaded.

What next

Use this often? Add JavaScript V to your Home screen.

Frequently asked questions

How does the JavaScript validator work?

It parses your code the way a JavaScript engine does before running it and reports the line, column and reason for the first syntax error, without running the code.

What is a JavaScript syntax error?

An error thrown when code has tokens, or an order of tokens, that doesn't fit JavaScript's grammar. It stops the script before it runs.

Does it support modern JavaScript?

Yes. It understands the latest syntax, including classes, async/await, optional chaining and import/export.

Does it find bugs in my logic?

No. It checks syntax only. Valid code can still have runtime errors or do the wrong thing.

Is my code run or uploaded?

No. It's only parsed, in your browser.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools