if (typeof(x)!="undefined") //if x exists
Now, in the past and in many of my scripts, I've resorted to simply using:
instead to check for x's existence. As people had pointed out to me, this is unreliable in that should x be set to false (ie: x=0), window.x will also return false, even though x is actually defined.
My question/discussion is, are there times when window.x is suffice/appropriate to detect the existence of a variable, or is it essentially considered incorrect and obsolete? My position is, as long as you're sure of the kind of values x will be receiving, that it will not contain Boolean values, window.x is valid and enough to detect x's existence.
What are your thoughts?