Web Analytics

Destructuring & Spread

Modern ~20 min read

Destructuring Assignment

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

Array Destructuring

HTML
CSS
JS

Object Destructuring

HTML
CSS
JS

Spread Operator (...)

The spread operator (...) allows an iterable (like an array) to be expanded in places where zero or more arguments or elements are expected.

HTML
CSS
JS

Rest Parameter (...)

The rest parameter syntax allows a function to accept an indefinite number of arguments as an array. It looks the same as spread, but is used in function definitions.

HTML
CSS
JS

Summary

  • Destructuring unpacks values from arrays or properties from objects into variables.
  • The Spread operator (...) expands iterables into elements.
  • The Rest parameter (...) collects multiple elements into an array.

Quick Quiz

Which operator is used to unpack an array?

A
Rest
B
Spread
C
Destructure
D
Unpack