3 ms·
My favorite which wasn’t included is NaN === NaN -> false In fact that’s exactly how isNaN(x) is implemented under the hood. It compares the argument to itsel
by mmoustafa 3y ago
My favorite which wasn’t included is
NaN === NaN -> false
In fact that’s exactly how isNaN(x) is implemented under the hood. It compares the argument to itself.
- gmiller123456 3y agoThis is from the IEEE-745 spec. The rationale is explained at the link below by a member of the baord at the time. https://stackoverflow.com/questions/1565164/what-is-the-rationale-for-all-comparisons-returning-false-for-ieee754-nan-values https://stackoverflow.com/questions/1565164/what-is-the-rati...
- patrec 3y agoAnd as can be seen from the weak provided rationale, the IEEE-754 spec rather sucks. Javascript would probably have been a better language had it diverged from it.
- anamexis 3y agoAs another comment points out, this isn’t JavaScript related, it’s just how the semantics of NaN in floating point works. Because, conceptually, 0/0 is not equal to -inf + inf. NaN is not a semantic value (it is a lack of one), so you can’t do semantic comparisons with it.
- paulddraper 3y agoThat's true in most languages. The opposite is almost more surprising.
- patrec 3y agoThe only language I can think off that does the right thing is Eiffel (https://bertrandmeyer.com/2010/02/06/reflexivity-and-other-pillars-of-civilization/ https://bertrandmeyer.com/2010/02/06/reflexivity-and-other-p...)