"SyntaxError" in JavaScript — What It Means and How to Fix It
What the JavaScript error "SyntaxError" means and how to fix it.
Published October 29, 2026
SyntaxError is thrown when the JavaScript engine cannot parse your code, so nothing in that file runs.
What it means and why it happens
Typical causes: missing brackets, quotes or commas, invalid JSON, reserved words or using modern syntax in old runtimes.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
SyntaxError: Unexpected token '}'
Practical examples
Code that triggers it
const o = { a: 1, b: 2,, }The fix
const o = { a: 1, b: 2 }Lint and format
npx eslint file.js
node --check file.jsCommon mistakes
- Trailing commas in JSON.
- Mismatched quotes.
- Using import in CommonJS files.
Key takeaways
- SyntaxError: SyntaxError is thrown when the JavaScript engine cannot parse your code, so nothing in that file runs.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
How do I find it?
The error shows file and line; use an editor with bracket matching.
How do I find which line caused SyntaxError?
The error message and stack trace show the file and line; start there and work backwards.