I was trying to find out more about the lodash _.clone which I thought made a copy of the data in an object and created a different object. However when I was testing in the con
That's how variables work in JavaScript, and most languages. Assignment of b = a
assigns the value of variable a
to variable b
. In languages where you're able to set a variable as a reference to another variable, there is usually a specific syntax for doing so; JavaScript does not have this feature.
Note that this can appear confusing because, in the case of objects, the value being assigned from a
to b
is a reference to the object, but this still doesn't "link" the variables themselves, it just "points" them to the same object. Modifying either variable (via assignment) will not affect the other variable, but any changes the object through either variable will be mirrored by both variables because, again, they point to the same object.