Edit
Just ran into a problem where I needed to copy and object and neither my solution below nor the accepted solution worked. This is because neither solution can perform a deepclone (when a property value is set as an object). Check out the warning in the documentation here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
Correct answer for a deep clone situation would be
y = {'a':2,'b':3}
z = JSON.parse(JSON.stringify(y))
This will solve the deep clone problem: like if y = {'a':{'c':4},'b':3}
End Edit
As Pranav put in the comments, both variable reference the same object. So what happens to one, happens to the other. To fix this you would have to create a copy of y without it referencing x:
y = {'a' : 2,'b': 3}
z = Object.keys(y)
let x = {}
z
for (i in z) {
x[z[i]] = y[z[i]]
}
Now:
delete y["a"]
y = {"b":2}
And:
x = {"a":1, "b":2}
The big takeaway here is that you have to create new object that looks exactly like y, but that doesn't reference y.