title: Why are changes to an array (passed in as param) maintained outside the function in one case, in the other not?
body: <p>I've recently learned about pass-by-reference. So I expected the behaviour of arr2, but have trouble understanding why arr1 is not changed outside of the function. Someone please enlighten me?</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>let arr1 = ([1, 2, 3, 4])
  let arr2;
  let a = 1
  let b = 3
  filterRange(arr1, a, b);
  
  function filterRange(arr1, a, b) {
    arr2 = arr1.filter(item =&gt; {
       return ((item &gt;= a) &amp;&amp; (item &lt;= b)) ? item : "";
    });
    arr1 = arr1.filter(item =&gt; {
       return ((item &gt;= a) &amp;&amp; (item &lt;= b)) ? item : "";
    });
    return
  }
  
  console.log(arr1) // [1, 2, 3, 4]
  console.log(arr2) // [1, 2, 3]</code></pre>
  </div>
  </div>
  </p>