How do I make obj2
the same as obj1
but not affected by the deletion?
Currently the name: 42
entry will be deleted from both objects.
Is it because of hoisting - that is, the deletion occurs before obj2
is created?
var obj1 = {
'name': 'John',
'age': 42,
}
var obj2 = obj1
delete obj1['name']
console.log(obj1)
console.log(obj2)