title: Object as reference to recursive function
body: <p>I'm trying to pass an object reference to a recursive function. I'm currently doing the following:</p>
  <pre><code>function Parent() {
      myBaseObject = {&quot;data1&quot;: &quot;123&quot;}
      emptyObjectForReference = {}
      myFunctionToUseObjects(myBaseObject, emptyObjectForReference)
      console.log(emptyObjectForReference)
  }
  
  function Child(myBaseObject, emptyObjectForReference) {
      emptyObjectForReference = Object.assign(myBaseObject, {&quot;Children&quot;: &quot;myChild&quot;})
  }
  </code></pre>
  <p>The above is very simplified, but explains well what I want to achieve. While this example could use a return statement just as easily - The point of having a reference, is due to the fact that <code>Child()</code> is supposed to be a recursive function that does some work to my object as it calls itself.</p>
  <p>Unfortunately, when I inspect <code>emptyObjectForReference</code> as the function is done - It still has it's initial value of <code>{}</code>. I would expect it to have the following output:</p>
  <pre><code>{
      &quot;data1&quot;: &quot;123&quot;,
      &quot;Children&quot;: &quot;myChild&quot;
  }
  </code></pre>
  <p>Does JavaScript, by default, not keep a reference to objects similar as to how it references e.g. a standard array? In case it is not possible - How would I then reference my object?</p>