Friday, 8 December 2017

JavaScript | isNaN() Function

NaN, standing for not a number, is a numeric data type value representing an undefined or unrepresentable value, especially in floating-point calculations.

The isNaN() function determines whether a value is an illegal number (Not-a-Number). This function returns true if the value equates to NaN. Otherwise, it returns false.


This function is different from the Number specific Number.isNaN() method. The global isNaN() function, converts the tested value to a Number, then tests it.

Number.isNaN() does not convert the values to a Number, and will not return true for any value that is not of the type Number.

isNaN(123)
Output: false
isNaN(-1.23)
Output: false
isNaN(5-2)
Output: false
isNaN(0)
Output: false
isNaN('123')
Output: false
isNaN('')
Output: false
isNaN(true)
Output: false

isNaN(undefined)
Output: true
isNaN('NaN')
Output: true
isNaN(NaN)
Output: true
isNaN(0 / 0)
Output: true
isNaN('Hello')
Output: true
isNaN('2005/12/12')
Output: true


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...