Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use the numeric predicate that matches your intent (isNaN vs isFinite)
Prefer Number.isNaN for 'not a number' checks; use Number.isFinite only when Infinity must also be rejected.
Bad example
| 1 | // intent: guard against a non-numeric id |
| 2 | if (!Number.isFinite(id)) return; |
Explanation (EN)
If the real concern is 'id parsed to NaN', isFinite obscures intent and also silently rejects Infinity, which may not be what you mean.
Objašnjenje (HR)
Ako je prava briga 'id se isparsirao u NaN', isFinite zamagljuje namjeru i k tome tiho odbija Infinity, sto mozda nije ono sto mislis.
Good example
| 1 | // intent: guard against a non-numeric id |
| 2 | if (Number.isNaN(id)) return; |
Explanation (EN)
Number.isNaN states exactly the condition you care about; use Number.isFinite only when finiteness (excluding Infinity) is genuinely required.
Objašnjenje (HR)
Number.isNaN tocno iskazuje uvjet koji te zanima; koristi Number.isFinite samo kad je konacnost (iskljucujuci Infinity) stvarno potrebna.