Skip to main content

Destructuring, Spread and Rest

Learn Destructuring, Spread and Rest (Phase 5 · Modern JavaScript and Destructuring (Essential), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Unpacking values • Array destructuring picks by position: const [a, b] = arr . Object destructuring picks by name: const { name, age } = user . • Rename with { name: userName } , give defaults with { role = "guest" } , skip items with commas [, second] . • Rest ( ...rest ) gathers the remainder; spread ( ...x ) expands an iterable or object into place.

More lessons in Phase 5 · Modern JavaScript and Destructuring (Essential)