5 ms·
> Also worth noting that it's not always true that `a >= b` means `!(a < b)` in JavaScript. `'a' >= null` and `'a' < null` are both false. For anyone wondering
by twiss 9y ago
> Also worth noting that it's not always true that `a >= b` means `!(a < b)` in JavaScript. `'a' >= null` and `'a' < null` are both false.
For anyone wondering why (like me), it's because +'a' returns NaN, and comparisons with NaN always return false (NaN <= 0, NaN >= 0 and NaN === NaN are all false).
Specifically, the Abstract Relational Comparison algorithm for 'a' < null returns undefined (instead of true or false), and all comparison operators return false when it does that. [1]
When neither argument is NaN, what the author wrote is true and a >= b === !(a < b).
[1]: http://www.ecma-international.org/ecma-262/8.0/index.html#sec-abstract-relational-comparison http://www.ecma-international.org/ecma-262/8.0/index.html#se...