It seems that the following technique for checking the existence of an object member produces an error because the \'bar\' parent object hasn\'t been declared before the che
var newVal = ('foo' in window && // could be typeof foo !== 'undefined' if you want all scopes
'bar' in foo &&
'myVal' in foo.bar) ? foo.bar.myVal : null;
To be fair to javascript, that reads almost like natural language.