NaN
In computing, NaN stands for Not a Number. It means the result of input is or unrepresentable. For example, division by zero in most Programming language returns NaN. Systematic use of NaN was introduced by the IEEE 754 in 1985, along with the other numbers such as infinities.
In JavaScript[change]
In JavaScript, <syntaxhighlight lang="javascript" class="" style="" inline="1">NaN == NaN</syntaxhighlight> or <syntaxhighlight lang="javascript" class="" style="" inline="1">NaN == other_value</syntaxhighlight> returns <syntaxhighlight lang="javascript" class="" style="" inline="1">false</syntaxhighlight>. using <syntaxhighlight lang="javascript" class="" style="" inline="1">===</syntaxhighlight> also returns <syntaxhighlight lang="javascript" class="" style="" inline="1">false</syntaxhighlight>. You can use <syntaxhighlight lang="javascript" class="" style="" inline="1">Number.isNaN(myVar)</syntaxhighlight> or <syntaxhighlight lang="javascript" class="" style="" inline="1">isNaN(myVar)</syntaxhighlight> to check if a value is NaN. there is difference between two functions. the <syntaxhighlight lang="javascript" class="" style="" inline="1">Number.isNaN(myVar)</syntaxhighlight> returns <syntaxhighlight lang="javascript" class="" style="" inline="1">true</syntaxhighlight> when the value is NaN when parsed to int. but <syntaxhighlight lang="text" class="" style="" inline="1">isNaN(myVar)</syntaxhighlight> returns <syntaxhighlight lang="javascript" class="" style="" inline="1">true</syntaxhighlight> when the value is currently NaN.[1]
For example:
<syntaxhighlight lang="javascript" class="" style="" inline="1">Number.isNaN('Hi!') // returns true because 'Hi!' in integer is NaN</syntaxhighlight>
<syntaxhighlight lang="javascript" class="" style="" inline="1">isNaN('Hi!') // returns false because 'Hi!' is not NaN</syntaxhighlight>
References[change]
- ↑ "NaN - JavaScript | MDN". developer.mozilla.org. Retrieved 2022-08-06.