3 ms·
well there is also one weird quirk I I assumed will be also included in this article: because a <= b is defined as !(a > b) then: 5 < NaN // false 5 == NaN
by Szpadel 1y ago
well there is also one weird quirk I I assumed will be also included in this article:
because a <= b is defined as !(a > b)
then:
5 < NaN // false
5 == NaN // false
5 <= NaN // true
Edit: my bad, this does not work with NaN, but you can try `0 <= null`
- lifthrasiir 1y agoIEEE 754 specifically prohibits that definition, and JavaScript indeed evaluates `5 <= NaN` to false.
- Szpadel 1y agoYep, my memory was incorrect here and I didn't had access to computer, but it is true with `0 <= null`
- kaoD 1y agoThis is because null coerces to 0 in JS so this is effectively 0 <= 0. NaN is already a `number` so no coercion happens. Note that == has special rules, so 0 == null does NOT coerce to 0 == 0. If using == null, it only equals undefined and itself.