javascript - parseInt() check for NaN isn't working properly -


this question has answer here:

i working on jquery plugin , need make sure value number, or string number. made following code, val variable may or may not number.

if (typeof val !== 'number') {//if "val" isn't number     if (typeof val === 'string' && parseint(val) !== nan) {//see if "val" string number         val = parseint(val);     } } 

but reason, while testing, if val string text, still returns parseint(val) !== nan true. later tested chrome console, , got:

incorrect return

as can see, 'asf' not-a-number. wherever returns true, should return false, , wherever returns false, should return true. can see tested make sure nan isn't string.

correct return

above can see return values same, time correct.

am missing something? or there different way supposed this?

nan not can compare to. need use :

isnan(parseint('asf')) // true

isnan(parseint('123')) // false


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -