Question from my Android app - React Quiz
If you want to check NaN equal to NaN:
isNaN(+NaN) === isNaN(+NaN)
For eg.:
const a = 'asdf234'
const b = 123
const c = '234asf'
console.log(isNaN(+a) === isNaN(+b)) // false
console.log(isNaN(+a) === isNaN(+c)) // true
Mark
NaNs work like that (being unequal to anything including itself) in most languages. Quite some Fortran code relies on ˋx != xˋ as a NaN-check.
Sometimes I wonder if there wasn't a better solution than NaNs for floating point arithmetic...
I'm not fond of ˋnullˋ in languages, but at least in most lanaguages you get a null pointer exception with that.
ˋNaNˋ is kind of like ˋnullˋ, but it just propagates until you discover it thousands of LoC away and have to spend an hour tracing it back.
But then again, floating point stuff is pretty complex and close to hardware, sand I don't know the constraints well enough to say if it was the right call.