I’ve finally been curious enough to find out why javascript does its voodoo magic to learn why not all object references are created equal.
Given the example:
var a, b, c, d;
a = 100; b = a;
c = {}; d = c;
b = 10; d.e = 'f';
console.log(a, b); // outputs 100, 10
console.log(c, d); // outputs object => e = 'f', object => e = 'f'
If all variables in javascript are objects, then what makes the use case with c and d cast explicitly as an Object so different than defining a and b as Number? Or, why will c and d be linked to one another, and not a and b?
All variables in JavaScript are not objects. There are native types as well.
canddare not linked to one another. They are pointing to the same object reference. If you were to reassigndto something else, it will not affectc.However, if you were to modify the object being referenced by
cord, it will modify the same object sincecanddare both referring to the same object as in your example.