Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Compare array/object contents, not references, for equality
Using === or identity comparison on arrays/objects only checks reference equality; compare lengths and elements (or use a deep/structural check) when you mean value equality.
Bad example
| 1 | if (selectedFilters === defaultFilters) { ... } // always false for distinct arrays |
Explanation (EN)
Distinct arrays with equal contents are unequal by reference.
Objašnjenje (HR)
Good example
| 1 | const sameLength = a.length === b.length; |
| 2 | if (sameLength && a.every((item, i) => item === b[i])) { ... } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Define equality by the consumer contract: identity, ordered element equality, set membership or deep structure.
Exceptions / Tradeoffs (EN)
Reference equality is correct for identity and memoization. every skips sparse holes; object elements still compare by identity unless the domain requires a deeper comparator.