var a = {a: 1, b: 2};
var b = a;
b.a = 3;
In the above code, b.a becomes 3, and a.a also becomes 3.
var a = {a: 1, b: 2};
function b(objeto) {
objeto.a = 3;
}
b(a);
In the above code, the value of a.a remains 1, since I am not editing the object a, but a copy of it (correct me if I am wrong).
Now here's the question:
var a = {a: 1, b: 2};
function copy(objeto) {
return objeto;
}
var b = copy(a);
b.a = 3;
In the code above, a.a is also worth 3. Why?