title: Better way to test for existence of a nested property in an object
body: <p>I'm working with javascript objects that have nested properties I need to test for, like</p>
  
  <pre><code>myObject = {
      'some' : {
          'nested' : {
              'property' : {
                  'foo' : 'bar'
              }
          }
      }
      ...
  }
  </code></pre>
  
  <p>The trouble is <code>myObject.some</code> might not exist, nor <code>myObject.some.nested</code>, and so on. So to test for the existence of <code>myObject.some.nested.property.foo</code> I have to do this:</p>
  
  <pre><code>if (myObject.some) {
      if (myObject.some.nested) {
          if (myObject.some.nested.property) {
              if (myObject.some.nested.property.foo) {
                  // do something with myObject.some.nested.property.foo here
              }
          }
      }
  }
  </code></pre>
  
  <p>because if I do <code>if (myObject.some.nested.property.foo)</code> and one of the parent properties doesn't exist, it throws the error:</p>
  
  <pre><code>TypeError: 'undefined' is not an object (evaluating 'myObject.some.nested.property.foo')
  </code></pre>
  
  <p>Is there a better way to test for nested properties without using so many <code>if</code> statements?</p>