0
Null & 0 value in js
Why : 0 >= null is true 0 <= null Is true But ! 0 == null Is false 0 < null Is false 0 > null Is false
3 ответов
+ 4
"The reason is that an equality check == and comparisons > < >= <= work differently. Comparisons convert null to a number, treating it as 0. That’s why (3) null >= 0 is true and (1) null > 0 is false.
On the other hand, the equality check == for undefined and null is defined such that, without any conversions, they equal each other and don’t equal anything else. That’s why (2) null == 0 is false."
https://javascript.info/comparison
+ 2
There is not much point in asking WHY. Javascript has a lot of wacky behavior with implicit conversions and coercions, that affect these operators. You just have to accept that it works like this. Because the language was designed this way. :)
+ 2
in addition to Lisa
JavaScript returns undefined for null and undefined in loosely Equal (==)
https://tc39.es/ecma262/multipage/abstract-operations.html#sec-islooselyequal