I wonder what happens when I try to assign one object to another?
function make(g: any, b: any) {
g = b;
}
let obj = {id: 1};
let obj2 = {id: 2};
make(obj, obj2);
console.log(obj);
console.log(obj2);
From point of view memory, what happens? As we know value is passed by link for object, it means g
will not be changed.
Why this code works different?
function make(g: any) {
g = {};
}
let obj = {id: 1};
make(obj);
console.log(obj);