Why did the object inside another object value got changed(x.address.city) and why did the name value changed?
why y address field changed to Pune and not the same worked for name?
const x = {
name: "ABC",
email: "ac@gmail.com",
mob: "12345",
address: {
city: "Mumbai",
state: "Maharastra"
}
};
const y = { ...x }
x.name = "XYZ";
console.log(x.name, y.name);
x.address.city = "Pune";
console.log(x.address.city, y.address.city);
Output:
XYZ ABC
Pune Pune