How should I test if a variable is defined?
if //variable is defined
    //do this
else
    //do this
if (typeof variable !== 'undefined') {
  // ..
}
else
{
     // ..
}
find more explanation here:
typeof null is ObjectUse the in operator.
'myVar' in window; // for global variables only
typeof checks will return true for a variable if,
undefined, orThe following examples will illustrate the second and third point.
// defined, but not initialized
var myVar;
typeof myVar; // undefined
// defined, and initialized to undefined
var myVar = undefined;
typeof myVar; // undefined
window or the global object. Any object can be used here instead. You've raised a good point about variables defined locally not being accessible here. I'll be interested in finding out if there's a way to determine undefinedness for local variables based only on the first criteria I have.