title: How to automatically add properties to an object that is undefined?
body: <p>Is there an easy way to automatically add properties to objects if they don't already exist?</p>
  <p>Consider the following example:</p>
  <pre class="lang-js prettyprint-override"><code>var test = {}
  test.hello.world = &quot;Hello doesn't exist!&quot;
  </code></pre>
  <p>This doesn't work because <code>hello</code> isn't defined.</p>
  <p>The reason why I'm asking this is because I have some existing objects for which I don't know if they allready have <code>hello</code> or not. I actually have a lot of these objects in different parts of my code.
  It is very annoying to always check if <code>hello</code> exists and if it doesn't create a new object like:</p>
  <pre class="lang-js prettyprint-override"><code>var test = {}
  if(test.hello === undefined) test.hello = {}
  test.hello.world = &quot;Hello World!&quot;
  </code></pre>
  <p>Is there a way to automatically create an object like <code>hello</code> in this example?</p>
  <p>I mean something like that in php:</p>
  <pre class="lang-php prettyprint-override"><code>$test = array();  
  $test['hello']['world'] = &quot;Hello world&quot;;   
  var_dump($test);
  </code></pre>
  <p>Output:</p>
  <pre class="lang-js prettyprint-override"><code>array(1) {
    [&quot;hello&quot;] =&gt; array(1) {
      [&quot;world&quot;] =&gt; string(11) &quot;Hello world&quot;
    }
  }
  </code></pre>
  <p>Ok it's an array but in js arrays it is the same problem as with objects.</p>