DEV Community

Discussion on: NaN - It's Not A Number🙄

 
pentacular profile image
pentacular • Edited

NaN isn't a numerical representation, because it isn't represented with numerals. :)

Thread Thread
 
radnerus profile image
Suren

Let's call it, a tried and failed numerical representation 😁 just for the fun of it😬

Thread Thread
 
pentacular profile image
pentacular

But in memory, it is still stored as a floating-point number, hence the typeof number.

Well, I don't think this quite follows.

Javascript could have specified that typeof NaN is not 'number' -- it isn't required because of any IEEE representation -- it could have just as easily decided that NaN is its own kind of thing, and said that typeof NaN === 'NaN'.

This is a kind of arbitrary decision, but you can think about the advantages and disadvantages of these decisions.

Personally, I think that it makes sense for typeof NaN to be 'number' because it is produced by the same kind of operations that produce numbers -- so it's something that you expect to pass through the same interfaces.

That is, things that expect 'number' type things should also expect NaNs.

But this isn't determined by IEEE or anything else really -- it's just something that the
people who developed Javascript decided because it was felt to be useful to most people most of the time.

Thread Thread
 
radnerus profile image
Suren

Great thought process! But typeof give the primitive types and they might have thought it's not worth having a separate type for a value that is used very less!

Thread Thread
 
somedood profile image
Basti Ortiz

I agree. NaN is really just an unfortunate (but equally appropriate) acronym for something that works like a number.