Table of Contents
In JavaScript, NaN is short for Not a Number. NaN is a JavaScript number that is not a legal number.
You get NaN when JavaScript cannot calculate a number.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript NaN</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Invalid Number Operations</h4>
<p id="demo"></p>
<script>
let x = 100 / "Apple";
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>

Result View Example
The type of NaN is number. This may look strange, but NaN belongs to the JavaScript number type.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript NaN</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>NaN is a Number</h4>
<p id="demo"></p>
<script>
let x = NaN;
document.getElementById("demo").innerHTML = typeof x;
</script>
</body>
</html>

Result View Example
JavaScript tries to convert numeric strings to numbers in arithmetic operations.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript NaN</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Numeric Strings</h4>
<p id="demo"></p>
<script>
let x = 100 / "10";
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
The result is 10, because "10" is converted to the number 10.

Result View Example
A non-numeric string cannot be converted to a number.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript NaN</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Non-Numeric Strings</h4>
<p id="demo"></p>
<script>
let x = 100 / "Apple";
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
The result is NaN, because "Apple" cannot be converted to a number.

Result View Example
You can use the JavaScript function isNaN() to find out if a value is not a number.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript NaN</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>Using isNaN()</h4>
<p id="demo"></p>
<script>
let x = 100 / "Apple";
document.getElementById("demo").innerHTML = isNaN(x);
</script>
</body>
</html>

Result View Example
NaN is the only JavaScript value that is not equal to itself.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript NaN</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>NaN is Not Equal to Itself</h4>
<p id="demo"></p>
<script>
let x = NaN;
document.getElementById("demo").innerHTML = x == x;
</script>
</body>
</html>
To test for NaN, use isNaN().

Result View Example
If you use NaN in a mathematical operation, the result will also be NaN.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript NaN</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>
<h4>NaN in Math</h4>
<p id="demo"></p>
<script>
let x = NaN;
let y = 5;
document.getElementById("demo").innerHTML = x + y;
</script>
</body>
</html>

Result View Example
NaN means Not a Number. But the type of NaN is number. Use isNaN() to check if a value is NaN.
Document in project
You can Download PDF file.