title: Swap entire arrays in Javascript
body: <p>When I try to make a function to swap 2 arrays, the original arrays are left unaltered.</p>
  
  <pre><code>function swap(x, y) {
      var temp = x; x = y; y = temp;
  }
  
  u=[1, 0];
  v=[0, 1];
  swap(u, v);
  console.log(u);
  console.log(v);
  </code></pre>
  
  <p>This results in u as [1, 0] and v as [0, 1]. The values haven't been changed after the function call to swap.</p>
  
  <p>On the other hand, if I do this without a function call:</p>
  
  <pre><code>u=[1, 0];
  v=[0, 1];
  var temp = u;
  u = v;
  v = temp;
  console.log(u);
  console.log(v);
  </code></pre>
  
  <p>Then they're swapped correctly, with u as [0, 1] and v as [1, 0].</p>
  
  <p>I thought Javascript arrays are passed by reference, not by value. Am I misunderstanding something here?</p>