01
Overview
Destructuring unpacks values from arrays/objects. Spread (...) expands iterables/objects. Rest (...) collects remaining. Default values in destructuring. Rename during destructuring. Swap variables without temp.
bash
const [a,b,...rest]=[1,2,3,4]; // a=1,b=2,rest=[3,4]
const {name:n="anon",age}=user;
const merged={...obj1,...obj2};
const copy=[...arr];
[a,b]=[b,a]; // swap02
Best Practices
Use destructuring for function params and return values. Spread for shallow copy/merge. Rest for variadic functions. Rename for clarity ({data:items}). Use defaults ({count=0}). Beware: spread is shallow only.
Ready to try Destructuring & Spread?
Visit the official site for the latest version and full documentation.
Visit Destructuring & Spread