title: Does JavaScript pass by reference?
body: <p>Does JavaScript pass by references or pass by values?</p>
  <p>Here is an example from <em><a href="https://en.wikipedia.org/wiki/Douglas_Crockford#Bibliography" rel="noreferrer">JavaScript: The Good Parts</a></em>. I am very confused about the <code>my</code> parameter for the rectangle function. It is actually <code>undefined</code>, and redefined inside the function. There are no original reference. If I remove it from the function parameter, the inside area function is not able to access it.</p>
  <p>Is it a closure? But no function is returned.</p>
  <pre><code>var shape = function (config) {
      var that = {};
      that.name = config.name || &quot;&quot;;
      that.area = function () {
          return 0;
      };
      return that;
  };
  
  var rectangle = function (config, my) {
      my = my || {};
      my.l = config.length || 1;
      my.w = config.width || 1;
      var that = shape(config);
      that.area = function () {
          return my.l * my.w;
      };
      return that;
  };
  
  myShape = shape({
      name: &quot;Unhnown&quot;
  });
  
  myRec = rectangle({
      name: &quot;Rectangle&quot;,
      length: 4,
      width: 6
  });
  
  console.log(myShape.name + &quot; area is &quot; + myShape.area() + &quot; &quot; + myRec.name + &quot; area is &quot; + myRec.area());
  </code></pre>