Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't conflate 0 with null/absent; use a clear sentinel
Distinguish valid zero from missing data with an explicit nullish check or a documented domain sentinel.
Bad example
| 1 | let page: number | null = null; |
| 2 | if (!page) { skip(); } // also skips when page === 0 |
Explanation (EN)
Truthiness conflates a valid zero with an absent value.
Objašnjenje (HR)
Good example
| 1 | let page: number | null = null; |
| 2 | if (page === null) { skip(); } |
Explanation (EN)
An explicit null check preserves page zero and the existing nullable contract.
Objašnjenje (HR)
Notes (EN)
When zero is a valid value and null means missing, use an explicit nullish check instead of truthiness. Select a sentinel only when the domain contract already reserves it.
Exceptions / Tradeoffs (EN)
Do not invent -1 if it can be a valid value or if a nullable type already expresses absence clearly. Decide separately whether undefined is also missing.