title: Javascript's assignment operation is to copy references?
body: <p>The basic example:</p>
  
  <pre><code>var b = 10;
  var c = b;
  b++;
  console.log(b,c);
  
  &gt;&gt; 11 10
  </code></pre>
  
  <p><code>c</code> looks like a copy of <code>b</code>.</p>
  
  <p>But in another case:</p>
  
  <pre><code>var x = {};
  var y = x;
  x.abc = 10;
  console.log(x.abc, y.abc);
  
  &gt;&gt; 10 10
  </code></pre>
  
  <p>Why is the <code>y</code> not a copy of <code>x</code>, but a reference which points to the same instance <code>x</code> points to?</p>
  
  <p>Also, I guessed <code>b++</code> creates another instance, so <code>b</code> points to the new instance but <code>c</code> points to the old one. However...</p>
  
  <pre><code>var u = 10;
  setTimeout(function() {
    console.log(u);
  }, 10000)
  u++;
  
  &gt;&gt; 11
  </code></pre>
  
  <p>If <code>u++</code> creates a new instance, then the <code>u</code> inside the anonymous function should point to the old <code>u</code>, shouldn't it?</p>