I always have such an intuition that an expression inside code can be mentally substituted by its evaluation result. However, the following two code snippets have different execution results.
let obj = {};
({a: obj.b, b: obj.a} = {a: 1, b: 2}); //* This line
console.log(obj); // {b: 1, a: 2}
versus
let obj = {a: 1, b: 2};
({a: obj.b, b: obj.a} = obj); //* and this line
console.log(obj); // {a: 1, b: 1}
I think the two starred lines are same IN MY BRAIN, but they have different execution results.
Is this an intentional design?
Object destructuring is just syntactic sugar for this:
but here, source and target are the same object
what you could do is