I would like to find out if a Javascript variable exists. This is what I have so far which was cobbled together from different forums:
function valueOfVar(foo){
var has_foo = typeof foo != 'undefined';
if(has_foo){
alert('1 = true');
return true;
}
else {
alert('1 = false');
return false;
}
}
Please note, I wish to pass in a string as foo. Example: valueOfVar(box_split[0]+'_2')
Now, I don't think this works because it returns true when certain variables don't even exist. In fact, it seems to return true all the time.
A JQuery implementation that works would also be great as I make use of this.
Thanks all for any help