title: Javascript array.push on clone array modify original array
body: <p>I found a really weird (for me) problem</p>
  
  <p>I have this global variable ARRAY</p>
  
  <pre><code>var A = [1,2,3,4]
  </code></pre>
  
  <p>then inside a function, I made local var and assign previous global var to it </p>
  
  <pre><code>function someFunc() {
       var X = A;
  }
  </code></pre>
  
  <p>I then made another local Var and assign it with the first local var's value </p>
  
  <pre><code>var Y = X;
  </code></pre>
  
  <p>I then push a new value to Y</p>
  
  <pre><code>Y.push(6);
  </code></pre>
  
  <p>but the, the new value (6) didn't only pushed to Y, but also to the 2 original array (X and A). What happened? Doesn't it supposed to only change Y?</p>
  
  <p>Please help, thank you.</p>
  
  <p>Here is my full code:</p>
  
  <pre><code>var A = [1,2,3,4];
  
  
  function someFunc(){
      var X = A;
      var Y = X;
      Y.push(6);
      console.log(A);
      console.log(X);
      console.log(Y);
  }
  
  $("#test").click(function(){
      someFunc();
  });
  </code></pre>
  
  <p>as you can see, it is triggered by clicking on element with id #test.</p>
  
  <p>All three console.log, even thought represent different variable, it return the same result, ARRAY with 6 on it</p>
  
  <p>Edit. Yes there is a similar question to this, but even though the problem is similar and the solution is identical, but the initial understanding is what different. In my question, I initially asked "Why", because I am not aware of those variable actually 'refer' to same array instead of 'assigning', so I have no idea if I should search for how to assign instead of refer, since I assumed that using <code>=</code> means assigning, sorry</p>