Modern JavaScript Essentials

Lesson 4 of 6

Objects and Destructuring

Objects group related data together. Destructuring and the spread operator make working with them much less repetitive.

JavaScript

What's happening

  • const { title, lessons } = course pulls properties straight out of an object into variables.
  • ...rest collects whatever is left over into a new array (or object).
  • { ...course, lessons: 7 } copies every property from course into a brand-new object, then overrides lessons, the original object is never mutated.

📝 Objects & Destructuring Quiz

Passing score: 70%
  1. 1.What does the spread operator do when used inside a new object literal, e.g. `{ ...course }`?

  2. 2.const { title } = course; is an example of object ____.

  3. 3.Writing `{ ...course, lessons: 7 }` mutates the original course object.