title: JS equivalent to C++ .at()
body: <p>Let's say I have an object:</p>
  
  <pre><code>var foo = {'bar1': {'baz1':1}};
  </code></pre>
  
  <p>And I try to access <code>foo['bar2']['baz2']</code>. If I was just trying to access <code>foo['bar2']</code>, JS would return <code>undefined</code>. But because I'm trying to get the next property after the undefined <code>bar2</code>, JS throws <code>TypeError: Cannot read property 'baz2' of undefined.</code></p>
  
  <p>Is there some automatic accessor for an object that first checks if <code>baz2</code> exists in <code>foo</code> before trying to call its properties? I know I could use a try/catch block or an if statement, but I was hoping for a function along the lines of C++'s <a href="http://www.cplusplus.com/reference/array/array/at/" rel="nofollow"><code>array::at</code></a>, that would check for me.</p>