javascript - Implicit cast/number check produces 'unexpected X' JSLint error -
this nothing serious, question out of curiosity. following script in jslint.com gives strange , 'unexpected' error. script works, still know if can explain error.
var hashvar = parseint(location.hash.replace('#',''), 10); if(hashvar-0 === hashvar){l();}
error: problem @ line 3 character 4: unexpected 'hashvar'.
enjoy weekend, ulrik
you want this:
var hashvar = parseint(location.hash.replace('#', ''), 10); if ( !isnan(hashvar) ) { l(); }
this code has same functionality original code.
btw, this:
if ( !isnan(hashvar) ) { l(); }
can further reduced this:
isnan(hashvar) || l();
;-)
explanation:
the return value of parseint
can be:
a) integer numeric value
b) nan
value
therefore, if want test whether return value integer or not, use isnan()
.
Comments
Post a Comment