d3DetectabilityOperational debt — how invisible misuse is to your safety net
Closest to 'default linter catches the common case' (d3). ESLint and TypeScript can detect || used where ?? is more appropriate (code_pattern explicitly mentions this), catching the most common mistake automatically.
e1EffortRemediation debt — work required to fix once spotted
Closest to 'one-line patch or single-call swap' (e1). The quick_fix is explicit: replace || with ??. This is a mechanical substitution that requires no refactoring, no parameter changes, and no cross-file coordination.
b1BurdenStructural debt — long-term weight of choosing wrong
Closest to 'minimal commitment' (b1). This is pure syntax choice—a naming convention for 'how to write default values'—with no load-bearing or cross-cutting implications. Once a team adopts ?? for defaults, every future maintainer simply writes new code the same way. No component is shaped by the choice.
t5TrapCognitive debt — how counter-intuitive correct behaviour is
Closest to 'notable trap' (t5). The misconception ('?? and || are interchangeable') is the canonical gotcha. Developers with || muscle memory from other languages will assume both behave the same way; many do eventually learn the distinction. The common_mistakes confirm this is documented and expected to trip people up, but it's not a catastrophic misunderstanding—once explained, the logic is sound.
About DEBT scoring →
scored by claude-haiku-4-5-20251001 · 2026-05-09 · reviewed by human
?? returns the right side only when the left is null or undefined — unlike ||, it does not trigger on 0 or empty string. Parallel to PHP's null coalescing operator.
Explanation
?? (ES2020) vs ||: ?? only checks null/undefined; || checks all falsy values (0, '', false, NaN). For API responses with 0 counts or empty strings, ?? prevents incorrect fallbacks. Logical assignment: ??= assigns only if null/undefined, ||= only if falsy, &&= only if truthy. PHP's ?? operator has the same semantics as JS ??. Optional chaining ?. accesses deeply nested properties safely without null checks.
Common Misconception
✗ ?? and || are interchangeable — || treats 0, '', false, and NaN as falsy and returns the right side; ?? only triggers for null and undefined, which is almost always what you want for default values.
Why It Matters
PHP APIs returning 0 for counts or empty strings for optional fields will incorrectly trigger || fallbacks, masking real data — ?? prevents these bugs.
Common Mistakes
Using || for default values when 0 or empty string are valid response values
Confusing ?. (optional chaining) with ?? (nullish coalescing)
??= not well-supported before 2021
Code Examples
✗ Vulnerable
// || incorrectly overrides valid 0 count:
const count = apiResponse.count || 0; // If count is 0, stays 0... wait no: 0 || 0 = 0
const label = apiResponse.label || 'Default'; // If label is '' — uses 'Default' incorrectly
// PHP parallel that also has this bug:
// $label = $response['label'] ?: 'Default'; // '' triggers fallback
🧱FUNDAMENTALS— new to this? Start with the ground floor.
JavaScriptjavascriptThe 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.