let a = 1;
let b = 2;
a = b;
b = a;
console.log(a, b);let a = 1;
let b = 2;
[a, b] = [b, a];
console.log(a, b);Bug: a = b makes a = 2. Then b = a reads the already-changed a (2) — so b becomes 2. The original value of a (1) is lost.
Explanation: Destructuring swap evaluates the right side first as a snapshot [2, 1], then assigns both simultaneously.
Key Insight: Destructuring swap is atomic — values are captured before assignment. Sequential swap loses the original without a temp variable.