tags:

views:

109

answers:

3

I’ve only been trying it in Firefox’s JavaScript console, but neither of the following statements return true:

parseFloat('geoff') == NaN;

parseFloat('geoff') == Number.NaN;
+2  A: 

Hello,

you should use the global isNaN(value) function call.

  • It is supported cross-browser
  • See isNaN for documentation

Examples :

 isNaN('geoff'); // true
 isNaN('3'); // false

I hope this will help you.

Jerome Wagner

Jerome WAGNER
I’m not Jerome Wagner, you are.
Paul D. Waite
You are right Paul D. Waite ;-) I fixed myself.
Jerome WAGNER
+3  A: 

isNaN(parseFloat("geoff"))

chiborg
Is there a need for paseFloat?
rahul
If you want an empty string to be interpreted as `NaN`, then yes. (I’m not saying you always would.)
Paul D. Waite
+6  A: 

Use

isNaN('geoff');

See isNaN

alert ( isNaN('abcd'));  // alerts true
alert ( isNaN('2.0'));  // alerts false
alert ( isNaN(2.0));  // alerts false
rahul
Thanks @David for fixing the typo.
rahul