Example 1 — Swap and Skip
Swap two variables and skip an item with a hole.
let a = 1;
let b = 2;
[a, b] = [b, a];
const [head, , tail] = ["x", "y", "z"];
console.log(a, b);
console.log(head, tail); How It Works
- Swap. Right-hand array builds new values, then assigns back.
- Skip. An empty slot ignores
"y".
