Favorites

JavaScript Validator

Check your JavaScript for errors and problems before they reach your website. Paste your code or open a .js file and the validator first checks the syntax, using the same rules as a browser, and points to the exact line and column of any mistake with a plain-English explanation of how to fix it.

When the syntax is valid it looks for warnings: variables that are used but never defined, variables that are never used, == where you probably meant ===, risky code and more. Click any message to jump to that spot. Your code is only read, never run, and it never leaves your browser.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Syntax errors, then warnings, for modern JavaScript.

JSInput

Results

Want to tidy the code too? The JavaScript Minify and Beautify tool lays it out neatly or makes it as small as possible.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

About this tool

Errors and warnings

  • Errors are syntax mistakes. A browser won’t run any of the script until they’re fixed, so a single missing bracket can break a whole page.
  • Warnings point to code that runs but is likely to be a mistake, such as a misspelt variable name, or that could behave unexpectedly.
  • Notes explain how the code was checked, for example as an ES module.

“Not defined” warnings

A variable that comes from somewhere else, such as $ from jQuery, require in Node.js or a library loaded by another script tag, is reported as not defined. Tick the matching option under Assume, or list it in a comment at the top of the file:

/* global Chart, dayjs */

How it checks

The syntax is checked with Acorn, a JavaScript parser that follows the latest language standard, so the errors match what a browser would report. Warnings come from JSHint, a long-established code checker. Both run in your browser; JSHint runs in the background with a time limit so the page never freezes.

Safe for any code

Your code is only read and analysed, never run, so it’s safe to check scripts you don’t trust, such as code copied from a forum or found on a compromised site. Nothing is uploaded or stored, apart from your option choices on this device.

Frequently Asked Questions

What does this JavaScript validator check?

First it checks that the syntax is valid, using the same rules as a browser, and shows the exact line and column of the first mistake with a suggestion for fixing it. If the syntax is valid it then looks for warnings, such as variables that are undefined or never used, == instead of ===, and risky code.

Does the validator run my code?

No. The code is only read and analysed, never run, so it’s safe to check code you don’t trust. Nothing is sent to a server either: everything happens in your browser.

Why is only one syntax error shown?

A syntax error stops the parser, just as it stops a browser from running the script, so everything after it can’t be checked reliably. Fix the error shown and the validator moves on to the next one, or to the warnings if there are no more errors.

Why do I get a warning for code that works?

Warnings are advice, not errors. For example, a variable you never use doesn’t break anything, but it’s often a sign of a typo or leftover code, and == works but can give surprising results. Switch off any warnings you don’t want under Options.

Why does it say a variable is not defined when it is?

The variable is probably defined in another file, such as a library loaded with its own script tag. The validator only sees the code you paste. Tick the matching environment under Assume (browser, Node.js, jQuery), or add a comment such as /* global myLibrary */ at the top of the file.

What does the JavaScript version option do?

It sets which language features are allowed. If you choose ES5, newer features such as let, arrow functions and classes are reported as errors, which is useful when the code must run in very old browsers. Leave it on Latest otherwise.

What is an ES module?

A module is a JavaScript file that uses import and export to share code, loaded with <script type="module"> or by a bundler. Modules always run in strict mode. The validator switches to module checking automatically when your code uses import or export.

Why are warnings missing after a certain line?

JSHint, which finds the warnings, is older than the syntax checker and doesn’t understand a few newer features, such as class fields. Your code is still valid, but warnings after the first line it can’t read aren’t shown. A note marks that line.

Is there a limit on the size of the code?

You can check up to a million characters at a time, which covers almost any single script. Very large files may take a few seconds to check for warnings; if it takes more than ten seconds, the warning check is stopped and only the syntax result is shown.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee