14
I was programming and I found something interesting but I was left with doubt in a situation.
I created an object and referenced it so:
a = {a:1,b:2}
And then I created another object and assigned the 'a' value on it:
b = a
Only when I changed the value of b
, the values of a
also changed.
This happened because I assigned not only the values of a
for b
but because I assigned the reference of one to another as well?
In Javascript, objects are at all times passed by reference, because, in fact, its value is always the reference and not the value itself
– Costamilam