FormatterHQ

JavaScript Validator & Syntax Checker

Check JavaScript for syntax errors before you ship or paste it. Errors are reported with line and column; valid code gets a short summary of its structure.

Input JAVASCRIPT
Output TEXT
Ready.

How to use the JavaScript Validator

  1. Paste your JavaScript into the Input editor, or use Sample, Upload file or Load URL to check a .js file.
  2. Press Validate. With Auto update on, the check re-runs as you type.
  3. Read the result: an error message with line and column in the status bar, or “No syntax errors found” with counts of lines, statements and functions.
  4. Fix the reported line, validate again, then use Copy or Download to take the report with you.

What the JavaScript validator checks

This JavaScript validator parses your code with Acorn, the small, standards-focused JavaScript parser used inside many build tools. If the code cannot be parsed, you get the parser's message together with the exact line and column of the problem. If it parses, the report confirms there are no syntax errors and summarizes the file: number of lines, top-level statements, functions, and whether it was parsed as an ES module or a classic script.

Syntax errors are the errors that stop a script from running at all. In a browser, a single one means none of the code in that file executes, so checking before deploying, or before pasting a snippet into a CMS or tag manager, saves a lot of debugging.

Example: finding a missing parenthesis

function total(items) {
  let sum = 0
  for (const i of items {
    sum += i
  }
  return sum
}

Result:

Unexpected token (line 3, column 25)

Column 25 is the { right after items: the parser expected the closing ) of the for header first. Parser messages point to where the code stopped making sense, which is usually at or just after the real mistake.

Errors it catches

  • Unbalanced brackets and braces, missing commas in object and array literals, unterminated strings and template literals.
  • Invalid syntax such as const obj = { a: 1, b: 2 ; or a stray ,,.
  • Early errors that the specification treats as syntax errors, such as redeclaring a let or const in the same scope (Identifier 'x' has already been declared).
  • await inside a function that is not async, reported as an unexpected token at the expression after await.

What a syntax check does not catch

A file can be syntactically valid and still fail at runtime or contain bugs. This validator does not report:

  • Undefined variables or typos in property names (documnet.title is valid syntax).
  • Type errors such as calling a number as a function.
  • Style or best-practice issues like unused variables, == instead of ===, or missing semicolons (automatic semicolon insertion makes most of those legal).
  • Placement rules that depend on context. Like Prettier, the parser is configured leniently: a top-level return or an import inside a block is accepted, and code that is invalid as a module (for example with statements) is re-parsed as a classic script.

Those are the job of a linter such as ESLint, or of TypeScript's type checker. A good workflow is: validate syntax here for quick checks, and use a linter in your editor and CI for everything else.

Supported syntax

The parser accepts modern ECMAScript: classes and private fields, optional chaining, nullish coalescing, async/await, top-level await in modules, BigInt, and ES module import / export. JSX is accepted as well, so React components can be checked. TypeScript and Flow type annotations are not JavaScript and are reported as syntax errors: let a: number = 1 fails at the colon. For TypeScript, run the TypeScript Formatter, which parses TS and reports syntax errors.

Reading common error messages

MessageUsual cause
Unexpected tokenMissing ), ] or , before the reported position, or an extra one at it
Unterminated string constantA quote was not closed on the same line; use a template literal for multi-line text
Identifier has already been declaredlet/const declared twice in the same scope
Unexpected keywordA reserved word used as a name, or await outside an async function
Unexpected token right after awaitThe surrounding function is missing the async keyword

After validation

Once the syntax is clean, tidy the code with the JavaScript Formatter or shrink it for production with the JavaScript Minifier. JSON is a separate format with stricter rules (no comments, double quotes only), so check it with the JSON Validator instead. Validation runs entirely in your browser; your code is not uploaded.

Frequently asked questions

Is this a JavaScript linter like ESLint?
No. It checks syntax only, which is what decides whether the code can run at all. Linters also report unused variables, suspicious patterns and style issues, and need a configuration.
Why is the error reported on a different line from my mistake?
The parser reports the first point where the code can no longer be valid. A missing closing bracket is often detected a line or more later, so check the lines just above the reported position too.
Can I validate TypeScript or JSX?
JSX is accepted. TypeScript type annotations are not valid JavaScript and produce a syntax error; use the TypeScript Formatter to check TS syntax.
Does it run my code?
No. The code is only parsed into a syntax tree, never executed, so it is safe to check untrusted snippets.
What does Source type: module mean?
The file was parsed as an ES module, which allows import and export and is always in strict mode. Code that is not valid as a module is parsed as a classic script instead.

Last updated September 26, 2026

Related tools

JavaScript Escape JavaScript escape online: convert special characters into escape sequences so text is safe inside JavaScript. JavaScript Formatter Beautify or minify JavaScript online: fix indentation, spacing and line breaks of messy or minified JS code. JavaScript Obfuscator Make JavaScript harder to read and copy by renaming variables and encoding strings. JavaScript Pretty Print Opinionated JavaScript pretty print with Prettier: identical output for any input layout, with indent, width, semicolon and quote options. JavaScript Tester Run JavaScript online and see console.log, warnings, errors and tables instantly in a safe, sandboxed browser console. JavaScript Unescape JavaScript unescape online: turn escaped sequences back into readable plain text instantly. Phone Number Validator & Formatter Validate phone numbers for 240+ regions and format them as E.164, international and national, with line type detection. TOML Validator Validate TOML files online against the TOML 1.0 spec. Find syntax errors by line and column and see the parsed data as JSON. UUID Validator & Decoder Validate UUIDs/GUIDs and decode version, variant and embedded timestamps for v1, v6 and v7 — many at once. Credit Card Validator Check credit card numbers with the Luhn algorithm, detect Visa, Mastercard, Amex and more, and verify length. Runs 100% locally. CSS Validator Validate CSS online: find unclosed braces, missing semicolons and other syntax errors. Email Address Validator Check email address syntax in bulk and flag typos in popular domains, disposable providers, role accounts and duplicates.