I am trying to do -
var a = {key1: "Value1", key2: "Value2"};
var b = a;
b.key3 = "Value3";
Though I was expecting a to console only {key1: "Value1", key2: "Value2"}
but if I do console.log(a) following is the result -
{key1: "Value1", key2: "Value2", key3: "Value3"}
For the time being I managed to make it work using ES6 Object.assign method like -
var a = {key1: "Value1", key2: "Value2"};
var b = Object.assign({}, a);
b.key3 = "Value3";
console.log(a); // {key1: "Value1", key2: "Value2"}
But I am interested to know about the cause of this in JavaScript.
FYI - I tried to search/google but unable to find as I don't know about the exact phase to follow.