I know objects are passed by reference in javascript. so when I'm mutating an object in some other functions then it should be reflected in the initial object, which is not a case here, I might be missing something, it would be great if someone could help. here in the modify function I'm changing the object obj1 but still, it is showing the initial object.
Code
obj1 ={
b:{
c:'c'
},
d:{
g:{
k:'k'
}
}
}
let modify = (obj1) => {
obj1 = obj1.b ;
}
console.log(obj1);
modify(obj1);
console.log(obj1);
Output
//output of console1
[object Object] {
b: [object Object] {
c: "c"
},
d: [object Object] {
g: [object Object] { ... }
}
}
//output of console2
[object Object] {
b: [object Object] {
c: "c"
},
d: [object Object] {
g: [object Object] { ... }
}
}