How to represent a Not a Number in Javascript

Description

NaN is short for Not a Number. In JavaScript, dividing a number by 0 returns NaN.

Any operation involving NaN always returns NaN. NaN is not equal to any value, including NaN.

Example


console.log(NaN /10); /*  w w w .  j ava 2  s. c  o m*/
console.log(NaN == 0); 
console.log(NaN == NaN); 

if ("a" != NaN){
   console.log("This is not a number");
}else{
   console.log("This is a number");
}

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions