SyntaxError
Thrown when code isn't valid JavaScript at all — the engine refuses to run any of the file, not just the broken line.
new SyntaxError(message)
Purpose
A SyntaxError means the text the engine tried to parse doesn’t form valid JavaScript. It’s caught
before execution begins, which is the key thing that distinguishes it from every other built-in
error type.
Example
console.log('Hello';
Uncaught SyntaxError: missing ) after argument list
Nothing in the surrounding file runs — not even statements written before the broken line — because the engine parses an entire script or module before executing any of it.
Common causes
- Mismatched or missing brackets, parentheses, or braces.
- A missing comma between object properties or array elements.
- Using a reserved word as an identifier (
let class = 5;). - Invalid characters left over from a paste, such as smart quotes (
'/') instead of straight quotes. - Duplicate parameter names in a strict-mode function — see Strict mode.
Distinguishing it from other errors
If a message names SyntaxError, the problem is structural and nothing executed. If it names
ReferenceError, TypeError, or another runtime error, the file was valid JavaScript and started
running — the problem only surfaced once a specific line executed. See
ReferenceError for that case.
Runtime notes
SyntaxError is part of ECMAScript, so the error type is standard everywhere; the exact wording of
the message is engine-specific (V8, used by Chrome and Node, phrases messages differently than
Firefox’s SpiderMonkey or Safari’s JavaScriptCore).