Destructuring & Spread Operator
How can you use destructuring to swap two variables without a temporary variable?
You can use array destructuring to swap two variables without a temporary variable by writing `[a, b] = [b, a];`. This elegant one-liner leverages array destructuring assignment to perform the swap. The right side `[b, a]` creates a new array with the values in swapped order, and the left side destructures these values back into the original variables. This technique is more readable and less error-prone than traditional approaches that use a temporary variable (`let temp = a; a = b; b = temp;`) or bitwise operations. It works because the right-hand side array is evaluated first, capturing the current values of `a` and `b`, and then the destructuring assignment happens as a separate step. This pattern is commonly used in modern JavaScript and is especially useful in algorithms like sorting where variable swapping is frequent.