← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

SyntaxError — Parse-Time Failures

JavaScript ES5 Beginner
debt(d1/e1/b1/t7)
d1 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'caught instantly (compiler/syntax error)' (d1). ESLint and TypeScript (both listed in detection_hints.tools) catch SyntaxErrors at parse time, before runtime. The syntax violation is immediately visible.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix explicitly states wrapping JSON.parse() in try/catch is the remedy, which is a single-line addition. Fixing malformed JSON strings (quotes) or removing eval() is also trivial.

b1 Burden Structural debt — long-term weight of choosing wrong

Closest to 'minimal commitment' (b1). SyntaxError handling is a localized concern—it affects only the code parsing JSON or evaluating strings. It does not impose structural debt across the codebase or shape future architectural choices. The choice to wrap JSON.parse() is a local best practice, not a load-bearing abstraction.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field states the canonical wrong belief: 'A SyntaxError in a function only prevents that function from running — it prevents the entire script from executing.' This directly contradicts developer intuition (that errors are function-scoped) and causes silent failures in production when malformed JSON from external APIs crashes the entire feature. This trap is serious because the obvious (wrong) assumption is enforced by how other runtime errors behave in JavaScript, making it a cognitive mismatch with similar concepts.

About DEBT scoring →

TL;DR

SyntaxError means JavaScript couldn't parse your code — the entire script fails to execute. Common causes: missing brackets, invalid JSON, reserved word misuse.

Explanation

SyntaxError is thrown at parse time before any code runs. The entire script block fails — not just the broken function. Common causes: missing closing brackets/braces, invalid JSON in JSON.parse() (single quotes, trailing commas), using reserved words as identifiers (class, let, const in non-strict modes), template literal syntax errors, regex syntax errors. JSON.parse() throws SyntaxError for invalid JSON — always wrap in try/catch. In modules, import/export syntax errors prevent the entire module graph from loading.

Common Misconception

A SyntaxError in a function only prevents that function from running — it prevents the entire script from executing.

Why It Matters

SyntaxErrors in production scripts cause complete feature failure. JSON.parse() SyntaxErrors from malformed API responses are a common source of uncaught errors.

Common Mistakes

  • Not wrapping JSON.parse() in try/catch for external data.
  • Using single quotes in JSON strings — JSON requires double quotes.
  • eval() throwing SyntaxError — another reason to avoid eval.

Code Examples

✗ Vulnerable
// JSON with single quotes — SyntaxError:
const data = JSON.parse("{'name': 'Paul'}"); // SyntaxError

// Trailing comma in JSON:
const config = JSON.parse('{"debug": true,}'); // SyntaxError
✓ Fixed
try {
    const data = JSON.parse(response);
} catch (e) {
    if (e instanceof SyntaxError) {
        console.error('Invalid JSON:', e.message);
    } else {
        throw e; // Re-throw non-syntax errors
    }
}

Added 22 Mar 2026
Edited 5 Apr 2026
Views 93
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 2 pings F 1 ping S 1 ping S 0 pings M
No pings yet today
Bing 1
Amazonbot 9 ChatGPT 8 Ahrefs 7 Unknown AI 6 Scrapy 5 SEMrush 5 Google 4 Bing 4 Claude 3 Brave Search 3 Majestic 2 Perplexity 2 Meta AI 2 Applebot 2 Qwen 1 PetalBot 1 Twitter/X 1
crawler 57 crawler_json 5 your_contextpost 1 pre-tracking 2
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
JavaScript javascript The programming language of the browser — it reads and modifies the page (the DOM), reacts to user events, and fetches data without reloading.

JavaScript is the only language browsers execute, so every interactive behaviour on the web goes through it. Its two defining traits — single-threaded event loop and loose typing (== coercion) — explain the majority of both its bugs and its design patterns.

💡 Default to const, use === always, and reach for let only when a value genuinely reassigns.

Ask Codex about JavaScript →
Syntax general Syntax is the set of rules that defines how code must be written for a programming language to understand it—like grammar rules for human languages.

Syntax is the first barrier to writing working code and remains relevant forever—even experts make syntax errors. Understanding syntax rules helps you read error messages, learn new languages faster, and write code that others can maintain.

💡 When you get a syntax error, check the line mentioned AND the line just before it—the actual mistake is often one line earlier.

Ask Codex about Syntax →
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Always wrap JSON.parse() in try/catch. Use JSON double quotes. Validate JSON with a linter. Use TypeScript to catch syntax errors at compile time.
📦 Applies To
javascript ES5 web cli
🔗 Prerequisites
🔍 Detection Hints
JSON.parse\(
Auto-detectable: ✓ Yes eslint typescript
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✗ Manual fix Fix: Low Context: Function Tests: Update


✓ schema.org compliant