Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP1universalStack: TypeScript
correctnesstruthinessstringsedge-cases
Be deliberate about !value vs Boolean(value) for string checks
!value and Boolean(value) differ for empty strings; choose the operator that matches the intended treatment of '' and double-check which falsy values you mean to catch.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | // Treats '' the same as missing, which may not be intended |
| 2 | if (!nickname) { |
| 3 | showAnonymous(); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | // Decide intent: empty string is still a value here |
| 2 | if (nickname === undefined || nickname === null) { |
| 3 | showAnonymous(); |
| 4 | } |
| 5 | // or, if '' should also count as "no nickname", keep !nickname but document it |
Explanation (EN)
Objašnjenje (HR)