I am trying to find out how to check if a variable exists or not to prevent an error if you use it when it's not defined.
This is what I thought would work:
.. But I get a 'could not get the type property' error in IE6 and decent browsers still say the variable isn't defined.Code:if (typeof varName === 'undefined') {}
I'm pretty certain for an object you can just do:
...but not with vars.Code:if(object) { }
So what is the best (all browser) way to check if a variable is defined?



Reply With Quote


Bookmarks