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: javascript
numbersparsingcorrectnessbug
Don't rely on a parsed-number fallback via ||, because NaN is truthy
parseFloat('') is NaN, which is truthy, so `parseFloat(x) || fallback` won't use the fallback for empty input; guard explicitly on Number.isNaN or on the raw string.
PR: hegnar-web · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | const gap = parseFloat(raw) || 20; // raw === '' -> NaN, NaN is truthy -> not 20 |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | const gap = parseFloat(raw.trim() || '20'); |
Explanation (EN)
Objašnjenje (HR)