This is kinda silly question, but I have noticed that when I, let's say declare one object
const test = {"foo": 1, "bar": 2}
console.log(test)
And then declare new variable, and give it value of the first object
const test2 = test;
Deleting key from the second variable, it deletes from both.
delete test2.foo
console.log(test2)
console.log(test)
Can someone explain why is this a thing, and how to avoid this problem?