Reputation: 1012
I'm creating a library and trying to send a string into the function and return it as a Number, while creating a conditional to determine if the string sent into the function is a number before I do the conversion.
var strNum = function(val){
if (!isNan(val)){
console.log('This is a string that can be converted')
parseInt(val)
return val
}else{
console.log ('This sting is not a "number"');
}
};
This is what I have but when debugging it I get an error of "ReferenceError: isNan is not defined if (val = !isNan(val)){" and I'm not sure why its isn't working!
Any thoughts?
Upvotes: 0
Views: 262
Reputation: 7144
it's isNaN
not isNan
.
There is no method named isNan
in javascript that's why its throwing reference error.
Upvotes: 6