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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -