As far as I remember I have been aware of this peculiarity where the type of NaN
is a number. Now, some people go out of their way to defend this as a 'common computer science principle', but in the end it still feels wrong to me (just because something is defined under the section numeric types doesn't make it a number).
Either way, this made me wonder, are there any typical situations where this makes code easier to read? Normally it just means you have to add on an extra check that it's a number and not NaN
which is quite a hassle. And for the life of me I can't remember ever having run into a situation where I wanted typeof NaN
to return number
. So, did I miss something? Or is it really as bad as it looks?