JavaScript AcademyProfessional Engineering

Learning object 29 of 100

Spread and rest explorer

Step through spreading arrays and objects into new ones and collecting the rest, and see which values are new and which are shared.

Loading…

What it shows

Spread expands values into a new array, object or argument list; later object properties override earlier ones. Rest does the opposite on the receiving side, gathering remaining arguments, items or properties into an array or object. Both create new top-level containers, but nested values are shared.

Guided experiment

  1. In Combine, step until basket exists. Was fruit changed?
  2. In Override, swap the order of ...account and plan. Predict the result first.
  3. In Rest, call total with five numbers.

Predict

const { a, ...rest } = { a: 1, b: 2, c: 3 }; What is rest?

Related

Lessons: Lesson 42: Spread and rest syntax

Projects: Project 9: Shopping Cart Price Calculator

Source: web/assets/js/objects/object-029.js in the companion repository.