Home >Web Front-end >JS Tutorial >What type is NaN in js
NaN in JavaScript stands for "Not-a-Number", which is a special data type used to represent values that cannot be represented as numbers. It is a reserved word whose type cannot be determined using the typeof operator and is often produced when performing mathematical operations on non-numeric strings or invalid input. NaN cannot participate in mathematical operations. Any operation performed on NaN will return NaN. You can use the Number.isNaN() function to detect NaN.
#What is NaN in JavaScript?
NaN, which stands for "Not-a-Number", is a special data type in JavaScript, used to represent values that cannot be represented as numbers.
Details:
typeof
operator special value. typeof NaN
will return "number"
, but NaN is not actually a number. <code class="javascript">const result = parseInt("abc"); // NaN const result = 10 / "hello"; // NaN</code>
<code class="javascript">console.log(NaN + 10); // NaN console.log(NaN * 5); // NaN</code>
Number.isNaN()
function. This function takes NaN as an argument and returns a boolean value: <code class="javascript">console.log(Number.isNaN(NaN)); // true</code>
Important:
typeof NaN
returns "number"
. Number.isNaN()
function to detect NaN. The above is the detailed content of What type is NaN in js. For more information, please follow other related articles on the PHP Chinese website!