Pass-by-reference JavaScript objects
<blockquote>
  <p>Please read the comments in the code below to know what I am trying
  to ask.</p>
</blockquote>

<p><strong>Expected Output:</strong> As per pass-by-reference mechanism in JavaScript, <code>objOne</code> is expected to log <code>{}</code> at the end, because <code>objTwo</code> was initialized with <code>{}</code>.</p>

<pre><code>var objOne = {
  x: 1,
  y: 2
};

var objTwo = objOne;

// change the x vlaue to 2 by objTwo
objTwo.x = 2;

// Change the value of key x in objOne as well - pass by reference mechanism
console.log(objOne); // { x: 2, y: 2 }

/*** Pass by reference is understood in code, above this comment ***/

// Now what if objTwo initialized with empty object
objTwo = {};

console.log(objOne); // { x: 2, y: 2 } but expected output = {}

// As per pass by reference mechanism. objOne is expected to log {}, because objTwo was initialized with {}.
</code></pre>