Loading JavaScript Validator...
Please wait a moment

How to Validate JavaScript - Step by Step Guide

Step 1

Add your JavaScript

Any plain JavaScript works, whether it is a browser script, a Node file or an ES module:

•
Paste it: drop the code into the editor on the left. On a phone, the Paste button reads your clipboard.
•
Upload a file: pick a .js, .mjs or .cjs file. An empty file is ignored and your current code stays where it is.
•
Try the sample: Sample loads a short shopping-cart snippet that parses cleanly. Delete a closing brace to see what an error looks like.

Example: JavaScript Code to Check

A small function like this one is enough to try it out:

function calculateTotal(items) {
  let total = 0;
  for (let i = 0; i < items.length; i++) {
    total += items[i].price;
  }
  return total;
}
Step 2

Read the result

About half a second after you stop typing, the code is parsed. Nothing is run. The validator:

•
Tries both loading modes: parses the code as a classic script and as an ES module, and tells you which one it passes as
•
Finds syntax errors: unclosed brackets, strings, template literals and comments, a missing comma, a duplicate let, await outside an async function, a broken regular expression
•
Names the wrong language: JSX, TypeScript and JSON pasted by mistake are called out by name

Example: Validation Results

The validator provides detailed feedback:

Valid JavaScript

No syntax errors found. Read as a classic script. It parses as an ES module too.

Step 3

Read the Error

When the code doesn't parse, you see the first error and where it is:

•
The reason: what the parser expected, in plain words where we could make it clearer
•
Line and column: the same line Node reports in almost every case (for an unclosed template literal we point at the opening backtick, which is more useful than the end of the file)
•
The line itself: printed with a caret (^) under the exact spot
Step 4

Fix and check again

Fix the code right in the editor and the result follows along:

•
Result for the current text: while a new check is pending the panel says Checking…, so an old "Valid" never sticks around
•
Copy the report: Copy puts the result, with line and column, on your clipboard
•
Download the report: saves the same text as javascript-validation.txt. For a few common mistakes beyond syntax, run the code through the JavaScript Linter

Frequently Asked Questions

What exactly does this validator check?

Whether your code parses as JavaScript, the same question Node answers with node --check. That catches unclosed brackets, strings, template literals, comments and regular expressions, a missing comma, a const without a value, the same let declared twice, await outside an async function, break outside a loop, a broken regex pattern and so on. You get the line, the column and the line itself with a caret under the spot.

Why does it say my code was read as a script, or as an ES module?

JavaScript can be loaded two ways, and they follow slightly different rules. A file with import or export, top-level await or import.meta only works as an ES module (type="module" in a browser, a .mjs file or "type": "module" in Node). Code with a with statement or an old-style octal like 010 only works as a classic script, because modules are always in strict mode. The validator tries both and tells you which one your code passes as.

Does it find bugs, type errors or style problems?

No. Valid here means the code can be parsed; it says nothing about whether it does the right thing. The code is never run, so a misspelled variable, a call to a function that doesn't exist, or a value of the wrong type will not show up. For a few common mistakes such as == instead of === or unreachable code, try the JavaScript Linter. For layout, use a formatter.

What happens if I paste JSX, TypeScript or JSON?

Each is named instead of getting a confusing parser message. JSX and TypeScript are not plain JavaScript, so browsers and Node reject them without a build step; the error points you to the JSX Validator or the TSX Validator. A JSON object is reported as JSON data, since a { at the start of a file reads as a block of code. A JSON array happens to be valid JavaScript, so it passes, with a note that it is data rather than a program.

Why does a top-level return pass with a warning?

Node wraps every CommonJS file in a function, so a return at the top of the file is legal there and is a common way to stop a script early. Browsers and ES modules reject it. The validator lets it through, the way node --check does for a .cjs file, and adds a warning so you know it will fail anywhere else.

Is my code uploaded or kept anywhere?

No. The check runs in your browser; the code is not sent to our server and nothing is kept. Reload the page and the editor starts empty. Copy and Download give you the validation report as plain text, not a changed copy of your code.

Related tools: JavaScript Linter, JSX Validator, TSX Validator and JavaScript Beautifier.