Undefined Test Not Working In Javascript
I'm getting the error 'foo' is undefined. in my script when i test my function with an undefined parameter. As far as I understand, This shouldn't be happening. My calling code: //
Solution 1:
You can't pass a variable that doesn't exist (undefined
, not null
...which does exist) into a function, it's trying to get the value of foo
to pass it when you call
var test = peachUI().stringIsNullOrEmpty(foo);
...and it isn't there, so you're getting the error on just that line, just as you would with a simpler case:
alert(foo);
Now if you tried to call it as a property of something, then it'd be valid, for example:
alert(window.foo);
Then undefined
gets passed in, because it's an undefined property on a known/present object.
Solution 2:
I get the error too, but it is is not related to your code, it is because you pass a variable that does not exist to a function. This works:
var foo = undefined;
var test = peachUI().stringIsNullOrEmpty(foo) ;
Btw. the error already tells you that the problem is not in your function, otherwise it be 'testString' is undefined
.
Post a Comment for "Undefined Test Not Working In Javascript"