title: Reverse array with for loops
body: <p>Quick JavScript question. In the following pieces of code I'm reversing the array <code>arr</code> that's being passed to the function <code>reverseArray</code>.</p>
  
  <p>In the first piece of code, it looks like that the local variable <code>arr</code> keeps changing even though inside the loop I am operating on the variable <code>newArr</code> which hold the initial value of <code>arr</code>. Hence the loop fails when arr.length reaches the values <code>3</code>.</p>
  
  <pre><code>function reverseArray (arr) {
      var newArr = [];
      var inArr = arr;
      console.log(inArr);
      for (i = 0; i &lt; arr.length; i++) {      
          newArr[i] = inArr.pop(i);       
      }   
      return newArr;
  }
  reverseArray(["A", "B", "C", "D", "E", "F"]);
  
  // OUTPUT: ["F", "D", "E"]
  </code></pre>
  
  <p>On the other hand, if I store <code>arr.length</code> on local variable <code>numArr</code>, then it works perfectly and reverses the array.</p>
  
  <pre><code>function reverseArray (arr) {
      var numArr = arr.length;    
      var newArr = [];    
      for (i = 0; i &lt; numArr; i++) {      
          let inArr = arr;
          newArr[i] = inArr.pop(i);       
      }
      return newArr;
  }
  
  reverseArray(["A", "B", "C", "D", "E", "F"]);
  
  // OUTPUT: ["F", "E", "D", "C", "B", "A"]
  </code></pre>
  
  <p>What am I missing?</p>