It seems that the following method of checking for the existence of a member of an object is creating an error because the parent object "bar" was not declared before validation, which means that I either have to declare it before validation, or use two 'typeof' expressions, of which there will be extra code:
var foo = {}, newVal = (typeof foo.bar.myVal !== 'undefined' ? foo.bar.myVal : null ); Error: foo.bar is undefined
So, how do you check if an element exists inside an undeclared object without an error?
I like javascript, but sometimes ...
Steve source share