0

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?

1
  • 4
    It's isNaN() (note the second upper-case N), not isNan(). Commented Mar 28, 2013 at 9:09

1 Answer 1

6

it's isNaN not isNan.

There is no method named isNan in javascript that's why its throwing reference error.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.