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
It can be done simply using the code below:
var newVal = (foo && foo.bar && typeof foo.bar.myVal !== 'undefined') ? foo.bar.myVal : foo.bar.myVal
A property is null or undefined, it will be evaluated as false so the above code will only process up to the first 'false' statement.