What Is NaN (Not a Number)?

In computing the NaN (Not a Number) is used to express given value or data is not a number. Especially systems and programming languages use different data types like characters, strings, text, numbers, floating-point numbers, etc. in order to store related data. The numbers are defined with the IEEE 754 and NaN is officially provided.

Numbers are one of the most popular data types where they can store integers, floating-point numbers. The NaN is used to express or specify the provided value can not be used as numbers. Programming languages like JavaScript provide the isNaN() method in order to check if a given variable or value is a number or not simply NaN or not NaN.

JavaScript isNaN() Method Examples

NaN is a property in JavaScript and retuned as a result of the isNaN() method. All provided variables and data can be tested if it is NaN or not like below.

NaN === NaN;        // false
Number.NaN === NaN; // false
isNaN(NaN);         // true
isNaN(Number.NaN);  // true
Number.isNaN(NaN);  // true

function valueIsNaN(a) { return a !== a; }
valueIsNaN(2);          // false
valueIsNaN(NaN);        // true
valueIsNaN(Number.NaN); // true

isNaN('hello wisetut');        // true
Number.isNaN('hello wisetut'); // false

Leave a Comment