I have a function:
function goError(thing){
console.log(typeof(thing)); //RETURNS A STRING 'UNDEFINED'
if(typeof(thing) != undefined){
console.log(thing); //RETURNS UNDEFINED
return thing;
}
throw 'Error: ' + thing;
}
I'm trying to get down to the error message. But when I pass through a parameter of undefined
, the function works correctly, which is not what I want.
When I console out the undefined variable, I get undefined
, but when I console out typeof(thing)
I get a string 'undefined'
. This string obviously isnt causing my error to kick in.
I could alter the function as follows, it works fine then and I can get to my error.
if(thing != undefined){
return thing;
}
But can I cause the error to kick in without altering the func?
What can I pass into my function that will cause the error?