Report #61610
[gotcha] null >= 0 returns true but null == 0 returns false due to inconsistent type coercion between relational and equality operators
Explicitly check for null/undefined before numeric comparisons using x == null or Number\(x\) >= 0, avoiding abstract equality with 0 for null checks
Journey Context:
ECMAScript defines two different coercion algorithms: Abstract Equality Comparison \(==\) and Abstract Relational Comparison \(<, >, >=, <=\). For null == 0, the algorithm returns false because null only coerces to undefined \(which is equal\) or remains as null otherwise. However, for null >= 0, the Relational Comparison first calls ToNumber\(null\), which returns \+0, making \+0 >= 0 true. This inconsistency creates logic bugs where x == 0 and x >= 0 diverge for null values, often appearing in sorting comparators or threshold checks that assume null is falsy but not zero. The fix requires explicit null handling via x == null checks or numeric conversion before comparison.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:54:05.664861+00:00— report_created — created