What is NaN in JavaScript?

NaN means “Not a Number”. It is the result of a maths operation that has no valid number as result.

console.log(Number("abc"));
console.log(0 / 0);
console.log(NaN === NaN);
console.log(Number.isNaN(NaN));
console.log(typeof NaN);

Output:

Tutorials Class - Output Window

NaN
NaN
false
true
number

NaN is the only value that is not equal to itself, so check it with Number.isNaN(). Its type is number.


Learn more about the similar topics:
Tutorials
JavaScript Variables
JavaScript Scope
JavaScript Data Types
JavaScript Type Conversion
JavaScript Operators
JavaScript Numbers and Math
Exercises & Assignments
Write a JavaScript program to add two numbers
Write a JavaScript program to swap two variables
Interview Questions & Answers
What are the data types in JavaScript?
What is the difference between == and === in JavaScript?
What is NaN in JavaScript?
What is the difference between null and undefined?
What is scope in JavaScript?
What is the difference between var, let and const?
What is hoisting in JavaScript?