Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use const/let; never use var
Prefer const by default and let only when reassignment is required.
Bad example
| 1 | var total = 0; |
| 2 | for (var i = 0; i < 3; i++) { |
| 3 | total += i; |
| 4 | } |
Explanation (EN)
Function-scoped var can capture a shared loop binding or permit reads before initialization.
Objašnjenje (HR)
Var s opsegom funkcije može uhvatiti zajednički binding petlje ili omogućiti čitanje prije inicijalizacije.
Good example
| 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)
For JavaScript or TypeScript bindings, use const unless the binding is reassigned, then use let. Check references, hoisting and closure behavior before migrating var. Also avoid reading a binding before its declaration.
Bilješke (HR)
U JavaScriptu i TypeScriptu koristi const ako se binding ne mijenja, inače let. Prije zamjene vara provjeri reference, hoisting i closure ponašanje. Ne čitaj binding prije deklaracije.
Exceptions / Tradeoffs (EN)
A legacy runtime may require transpilation before block-scoped syntax; do not mechanically change var when existing hoisting or global binding behavior is relied upon.