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).
frontend ruleP0universalStack: typescript
variablesbugsreadability
Use const/let; never use var
Prefer const by default and let only when reassignment is required.
Created: Feb 10, 2026
Bad example
Old codets
| 1 | var total = 0; |
| 2 | for (var i = 0; i < 3; i++) { |
| 3 | total += i; |
| 4 | } |
Explanation (EN)
var is function-scoped and can cause subtle bugs with hoisting and unexpected captures.
Objašnjenje (HR)
var je function-scoped i može uzrokovati suptilne bugove zbog hoistinga i neočekivanih captureova.
Good example
New codets
| 1 | let total = 0; |
| 2 | for (let i = 0; i < 3; i++) { |
| 3 | total += i; |
| 4 | } |
| 5 |
|
| 6 | const label = 'done'; |
Explanation (EN)
Block scoping matches intent, reduces accidental reassignments, and improves readability.
Objašnjenje (HR)
Block scope bolje odgovara namjeri, smanjuje slučajne reassignment-e i poboljšava čitljivost.
Notes (EN)
Also: do not use variables before their declaration.
Bilješke (HR)
Također: ne koristi varijable prije deklaracije.