Tech Kraft

Documentum, AWS, Java, Ruby on Rails, Linux, Windows, App Servers


Javascript: There are two isNaN functions!

Javascript has two separate functions to test whether the value being tested is a Number or not.

isNaN()

The first one is a global isNan() function, which strictly tests whether the test value is a Number or not. So if you pass a string to this function, it will return true. For example, the following will all return true (i.e. the following arguments are all strictly Not A Number)

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

The global isNaN() function, converts the tested value to a Number, then tests it. This may not be the behavior you are looking for, though.

Number.isNaN()

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. So it has the following behavior:

Number.isNaN(123) //false
Number.isNaN(-1.23) //false
Number.isNaN(5-2) //false
Number.isNaN(0) //false
Number.isNaN('123') //false
Number.isNaN('Hello') //false
Number.isNaN('2005/12/12') //false
Number.isNaN('') //false
Number.isNaN(true) //false
Number.isNaN(undefined) //false
Number.isNaN('NaN') //false
Number.isNaN(NaN) //true
Number.isNaN(0 / 0) //true


Leave a comment

About Me

Senior Software Engineer professional with over 16 years of success with multiple open source technologies and various Content Management platforms and solutions.

Proven technical abilities through numerous projects involving enterprise web application design and development, application installation, configuration and support, and workflow and collaboration system designs.

  • Ability to learn new technologies and platforms quickly and apply them to the task at hand.
  • Excellent analytical skills, and strong communication and collaboration abilities.
  • Technical emphasis in including but not limited to Java, Ruby on Rails, Documentum and Alfresco
    in both Linux and Windows based environments

Newsletter