Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 22, 2020 02:15 pm GMT

NaN - It's Not A Number

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-Number the same as the value of Number.NaN. In modern browsers, NaN is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it. It is rather rare to use NaN in a program.

Hear the value of NaN is Number.NaN. But, wait!

NaN === Number.NaN // false

Maybe because of the type you think

NaN == Number.NaN // false

Somewhat reasonable explanation started here when I followed the links.

With a lot of confusion around NaN, let us see how we could arrive at a value of NaN.
There are 5 different operations which could result in NaN.

  • Numbers that can't be parsed
parseInt('Integer')  NaNNumber('%^@#')  NaN
  • Math operation where the result is not a real number
Math.sqrt(-1);  NaN
  • The operand of an argument is NaN
NaN + 20  NaN60 * NaN  NaN
  • Indeterminate form
0 * Infinity  NaN
  • Any operation that involves a string and is not an addition operation
"Integer" * 5  NaN

For geekier discussions, reach out to me on twitter at @radnerus93, DM always open.


Original Link: https://dev.to/radnerus/nan-it-s-not-a-number-f3a

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To