title: JS object copy by value vs copy by reference
body: <p>I was playing with chrome console and noticed something which I couldn't understand. I know in JS variables are copied by value and objects are copied by reference. Below code works fine as expected which outputs 2 and proves JS objects work as reference:</p>
  
  <pre><code>var objA = {a: 1};
  var objB = objA;
  objA.a = 2; 
  objB.a; // 2
  </code></pre>
  
  <p>However this code doesn't work as it should. I expected objB.a to output <code>2</code> but it gives <code>1</code> instead. Why? </p>
  
  <pre><code>var objA = {a: 1};
  var objB = objA;
  objA = {a: 2};  //Assigned whole object here instead property.
  objB.a; //1 - Shouldn't this be 2 ??
  </code></pre>