← Home ← Codex ← DEBT
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 47
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 1 ping S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
SEMrush 1
Amazonbot 6 ChatGPT 5 Scrapy 5 Unknown AI 4 Ahrefs 3 Majestic 2 Google 2 Perplexity 2 Claude 2 Meta AI 2 Bing 1 Qwen 1 SEMrush 1
crawler 30 crawler_json 4 pre-tracking 2
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