JSJavaScript · Lesson 10 of 14
Destructuring, Spread & Rest
ES6 destructuring lets you unpack arrays and objects in a single expression. Combined with spread and rest, it makes JavaScript feel dramatically less verbose. Fair warning: it also makes clever one-liners dramatically easier to write.
◆ Note
Spread creates shallow copies — nested objects are still references. { ...obj } and [...arr] are fine for one-level-deep copies. For deep cloning, use structuredClone(obj) (modern JS) or JSON.parse(JSON.stringify(obj)) (lossy but widely supported).
Spread creates shallow copies — nested objects are still references. { ...obj } and [...arr] are fine for one-level-deep copies. For deep cloning, use structuredClone(obj) (modern JS) or JSON.parse(JSON.stringify(obj)) (lossy but widely supported).