<, >, <= and >= all use one abstract operation, IsLessThan(x, y), which returns true, false or undefined ("not comparable"):
- Convert both operands with
ToPrimitive(…, number): objects tryvalueOfbeforetoString. - If both primitives are strings, compare them code unit by code unit; a proper prefix is less. No conversion to numbers happens, so
'10' < '9'istrue. - A BigInt and a string: parse the string with
StringToBigInt; if that fails, the result is undefined. - Otherwise convert both with
ToNumericand compare numerically. A BigInt and a Number compare by exact mathematical value. If either side isNaN, the result is undefined.
The operators then map that result:
x < yis IsLessThan(x, y);x > yis IsLessThan(y, x). Undefined becomesfalse.x >= yis not IsLessThan(x, y);x <= yis not IsLessThan(y, x). Undefined becomesfalsehere too, rather than being negated.
So null >= 0: null converts to 0, 0 < 0 is false, and >= returns the negation, true. null > 0 is false (it asks 0 < 0). Meanwhile null == 0 is false, because loose equality has its own algorithm in which null equals only null and undefined. The relational operators and == were never designed to agree.
undefined converts to NaN, so every relational comparison with it is false, including undefined >= 0.
One subtlety: x > y swaps the operands, so the spec passes a leftFirst flag that still converts x before y, keeping left-to-right order for side effects.