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
functionsdefault-parameterscorrectness
Prefer default parameter values over internal fallbacks
Express an optional argument's fallback with a default parameter; it's clearer than reassigning inside the body and avoids the falsy-zero bug where a valid 0 gets replaced by the fallback.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | export const getFirstHour = (customHour?: number): number => { |
| 2 | const firstHour = customHour ? customHour : FIRST_HOUR; // 0 falls through to FIRST_HOUR |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | export const getFirstHour = (firstHour: number = FIRST_HOUR): number => { |
| 2 | // 0 is preserved |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)