The proper syntax to destructure an object to existing variables is
({x, y} = {x: 1, y: 2});
This allows {x, y} = {x: 1, y: 2}
to be an expression. Otherwise {x, y}
is interpreted as a block with comma operator, this results in Unexpected token =
error.
It works without parentheses and a semicolon in console because it is treated as an expression there. This is efficiently same thing as
console.log({x, y} = {x: 1, y: 2});