However, the >= operator in fact works in a very different way, which is basically to take the opposite of the < operator
That's not ture, >= and <= operators just convert both sides to numbers if they have different types and that's why null >= 0 returns true because 0 == 0 is true.
You can test that withNaN and will return false :
NaN == 0 // false
NaN > 0 // false
// But ...
NaN >= 0 // false
You can see that NaN < 0 returns false and >= operator doesn't return the opposite.
So >= and <= operators are just shorthands :
x >= y → x > y || x == yx <= y → x < y || x == y
and if x and y have different types they will be converted to numbers before comparing.
That's not ture,
>=
and<=
operators just convert both sides to numbers if they have different types and that's whynull >= 0
returns true because0 == 0
is true.You can test that with
NaN
and will return false :You can see that
NaN < 0
returns false and>=
operator doesn't return the opposite.So
>=
and<=
operators are just shorthands :x >= y
→x > y || x == y
x <= y
→x < y || x == y
and ifx
andy
have different types they will be converted to numbers before comparing.