title: Switching objects in an array without making a new array
body: <p>I'm self-studying data structures and am clearly not grasping how referencing works.</p>
  
  <p>I'm trying to reverse an array WITHOUT creating a new array. So I think I need to store one of the values in a local variable (x in this case) but even so, it's not updating.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function reverseArrayInPlace(arr){
      for (var i = 0; i &lt; Math.floor(arr.length / 2); i++){
          let x = i;
          arr[arr.length - 1 - i] = arr[i];
          arr[i] = arr[x];
      }
      return arr;
  }
  
  let arrayValue = [1, 2, 3, 4, 5];
  reverseArrayInPlace(arrayValue);
  console.log(arrayValue);</code></pre>
  </div>
  </div>
  </p>
  
  <p>My expected result should just be any array reversed.</p>
  
  <p>// → [5, 4, 3, 2, 1]</p>
  
  <p>But I'm just getting</p>
  
  <p>// → [1, 2, 3, 4, 5]</p>