title: Convert an array to a list of nested objects - Eloquent Javascript 4.3
body: <p>I am looking at this exercise from the book Eloquent Javascript, Chapter 4 - <a href="https://eloquentjavascript.net/code/#4.3" rel="nofollow noreferrer">A List</a> for quite some time and I'm trying to understand how this particular function works: </p>
  
  <pre><code>function arrayToList(array) {
    let list = null;
    for (let i = array.length - 1; i &gt;= 0; i--) {
      list = {value: array[i], rest: list};
    }
    return list;
  }
  
  console.log( arrayToList([10, 20]));
  // → {value: 10, rest: {value: 20, rest: null}}
  </code></pre>
  
  <p><br>
  Even after adding the <code>list</code> to the Watch window in the Debugger I can't clearly see the following:</p>
  
  <p><br>
  1.  How does exactly the statement from list =  <code>{value: array[i], rest: list};</code> get appended to the <code>rest</code> property of the nested object, during each iteration?</p>
  
  <p><br>
  Obviously, the dot <code>.rest</code> or bracket <code>['rest']</code> notation are not being used, and it is not being explicitly specified that during every following iteration we are referring to the property of the object or its later nested objects, so how does it get appended to the property of each next nested object.</p>
  
  <p>I am expecting for every iteration to overwrite the contents of the <code>list</code> object, but this is not the case.</p>