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)
- (C) https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html
- (C++) http://www.cplusplus.com/reference/cmath/nan-function/
- (C#) https://docs.microsoft.com/en-us/dotnet/api/system.double.nan?view=netframework-4.7.2
- (D) https://dlang.org/spec/type.html
- (Java) https://www.geeksforgeeks.org/nan-not-number-java/
- (PHP) https://www.php.net/manual/en/function.is-nan.php
- (Python) https://docs.scipy.org/doc/numpy/reference/generated/numpy.isnan.html
References
- https://stackoverflow.com/questions/6976721/is-nan-equal-to-nan
- https://stackoverflow.com/questions/19800415/why-does-ieee-754-reserve-so-many-nan-values
- https://www.ecma-international.org/ecma-262/6.0/#sec-value-properties-of-the-global-object-nan
- https://en.wikipedia.org/wiki/NaN
- https://en.wikipedia.org/wiki/IEEE_754
- https://ieeexplore.ieee.org/document/4610935
- https://techterms.com/definition/nan
No comments:
Post a Comment