According to MDN,
NaN is a property of the global object. In other words, it is a variable in global scope.
The initial value of NaN is Not-A-N...
For further actions, you may consider blocking this person and/or reporting abuse
I have not really used NaN directly in years, I wonder why this is. Oh this reminds me, I found a method I either forgot about or had completely missed.
Number.isInterger. β¨ learn a new thing every day.Just to clear things up,
NaNis just a specially formatted number defined by the IEEE 754 standard, hence having thetypeofnumber.NaNsimply represents a "floating-point arithmetic exception", but it is still laid out in memory as a floating-point number.Let's be clear that NaN is not a number in IEEE. :)
It is a value that is used as a code to indicate that a floating point exception has occurred and the value does not represent a number.
But in memory, it is still stored as a floating-point number, hence the
typeofnumber. Although it is not exactly a correct description, it is kinda correct from the viewpoint of low-level memory. The bits of the "number" are just specially formatted to indicate an arithmetic exception.I just meant to clarify that
typeof NaN === 'number'isn't as unfounded as it first seems. πNaN is the numerical representation of a value which was tried to be cases as a number, evaluated as an expression or directly assign a value of NaN. So it's time would be a "Number'. But wouldn't make sense if 2 NaN is equal.
NaN isn't a numerical representation, because it isn't represented with numerals. :)
Let's call it, a tried and failed numerical representation π just for the fun of itπ¬
I discovered this week that NaN is truthy. A bunch of state values were showing undefined in a React app. However, it used server side rendering to initialize the state, and they started as NaN, causing a bunch of things to flash from one value to the next when the state updated. That was a fun two hours.
I would be more careful when dealing with numbers in state of numbers nowπ
Hi Suren, nice article! :-)
After reading your post I decided to share my thoughts on the NaN special value here in the comments, but then I noticed that comment started to get bigger so I decided to write a post π
Here's the link to my post. I hope it helps ππ
Β‘Keep up the good work!
Good one, Diegoβ¨
It's probably worth noting that NaN === NaN is false, which is why there's isNaN to detect it.
True!
Oh wow, I just realized after reading this, that I have never really looked at what really is NaN.π
Glad it helped you, Tanvesh! Now you know and that's great π
Great, thanks