Wednesday, April 17, 2019

Refresh: Not a Number (NaN)

Today I answered the question from Enki on NaN (i.e. not a number). I failed (along with 40% of other developers).


My failure could be due to my lack of experience using NaN. Nonetheless, here's the explanation by Enki.


Wow, I never knew that there was an IEEE 754 standard corresponding to the NaN value. So naturally, I had to learn more because the simple explanation from w3schools was insufficient and I never ran into a case where I had to examine NaN === NaN or even NaN == NaN. Since I already knew what the comparison operator (equal type, equal value), I thought it could apply the same understanding as with the null object and undefined constant (see JavaScript data types).



But, I didn't see any quick examples from w3schools (my main online reference for quick understandings on standard web languages). Before I start digging, I refreshed my understanding from the quick lesson JavaScript's Numbers and now notice this new reference to the IEEE 754 standard. I definitely don't remember seeing that there, but could just be me.


Integers have an accuracy up to 15 digits - got it. Now, JS Numbers are always 64-bit double data types - got it. Reading further on this page, definitely don't remember an "Infinity" and I rarely remember the HexDecimal. Needless to say, refreshed my understanding of NaN.




Finally, refreshed my understanding with using the equality operator on objects. Unless comparing standard JavaScript data types (implicitly via var declaration), the object type doesn't matter because whenever two defined objects are compared the result is always false.

Mozilla provides further explanation with comparing NaN and its usage.



Okay, that's cool, but where did Enki get there explanation saying that all NaN will never have the same value?

I don't know and it would help if Enki did provide this online reference.

ICYMI like me, NaN is not just used in JavaScript. Surprise, that's right! So, double check your programming language if it has NaN (and Infinity).

Happy Coding!


Programming Languages using NaN (Brief List)



References






No comments:

Post a Comment