Report #83597
[gotcha] Relational operators coerce null to 0 but abstract equality does not \(null >= 0 is true, null == 0 is false\)
Always use strict equality \(=== and \!==\) for comparisons. For numeric checks against null/undefined, explicitly handle them: \`if \(x \!= null && x >= 0\)\` or \`if \(x ?? 0 >= 0\)\` with caution. Never rely on relational operators \(>, <, >=, <=\) with nullable values without explicit checks.
Journey Context:
ECMAScript defines two different abstract operations for comparisons. The Abstract Equality Comparison \(==\) treats \`null\` and \`undefined\` as equal to each other but not equal to any other value, including 0. However, the Relational Comparison algorithm \(used for <, >, <=, >=\) first converts both operands to primitives, then to numbers. \`null\` is converted to 0, so \`null >= 0\` becomes \`0 >= 0\`, which is true. Similarly, \`null > 0\` is false. This inconsistency causes logic errors when filtering arrays or validating form inputs where \`null\` \(e.g., from a JSON response\) is compared against a threshold. Developers often assume \`>=\` and \`==\` share coercion rules. The only safe path is strict equality and explicit null handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:54:26.937058+00:00— report_created — created