I was reading javascript questions where i found this piece of code
var a={},
b={key:'b'},
c={key:'c'};
a[b] = 123;
a[c] = 456;
console.log(a[b]); // o/p - 456
can anybody make me understand this code why and how it is printing 456?
And I think we can use dot i.e a.b = 123 and string a['b'] = 123 approach to add property to an object.
bis an object, when used as key converted to string as[object Object],cis again an object which will be converted to string when used as key. This will overwrite the previous value, thus 456.bproperty on the object.