> I think SQL behaves this way
Yes. It's also how NaNs are supposed to work according to IEEE-754.
The only reason why it can be strange in javascript is that it's pretty common to encounter nans in JS as the language tries very hard not to throw errors and likes nans a lot (so `parseInt('foo')` returns NaN instead of `null` or an error), whereas it's very rare in other languages. Pretty much all languages have nans, and all nans behave this way. Here it is in Python:
>>> float('nan')
nan
>>> float('nan') == float('nan')
False
>>> float('nan') != float('nan')
True
>>> a = float('nan')
>>> a == a
False
>>> import decimal
>>> decimal.Decimal('NaN')
Decimal('NaN')
>>> decimal.Decimal('NaN') == decimal.Decimal('NaN')
False
>>> a = decimal.Decimal('NaN')
>>> a == a
False
edit: now that I think about it, there is a difference: in SQL, all operations involving `NULL` (including comparisons) return `NULL`, so `NULL = NULL` => `NULL` and `NULL != NULL` => `NULL`.
If there’s a WTF, it’s that NaN === NaN is either true or false. If I were writing a language, it might be undecideable. But if you end up with:
You are opening up the “Hopelessly Egocentric Null” can of worms:https://github.com/raganwald/homoiconic/blob/master/2009-02-...