ES6 - Number.NaN


Advertisements


Unquoted literal constant NaN is a special value representing Not-a-Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number.

Syntax

var val = Number.NaN; 

Example

var dayOfMonth = 50; 
if (dayOfMonth < 1 || dayOfMonth > 31) { 
   dayOfMonth = Number.NaN 
   console.log("Day of Month must be between 1 and 31.") 
} else { 
   console.log("day of month "+dayOfMonth) 
}  

Output

Day of Month must be between 1 and 31.

es6_number.htm

Advertisements
E-Books Store