Check out a free preview of the full JavaScript: The Recent Parts course

The "Destructuring Solution" Lesson is part of the full, JavaScript: The Recent Parts course featured in this preview video. Here's what you'd learn in this lesson:

Kyle live codes the solution to the exercise.

Preview
Close

Transcript from the "Destructuring Solution" Lesson

[00:00:00]
>> Kyle Simpson: All right, well let's talk about this destructuring exercise, we'll take a look at how to solve it. We start with the defaults object, but our goal is to not have to manage this in a separate object. Our goal is to have those values in line into our destructuring pattern.

[00:00:18]
So for now comment that object out and then I'll make sure to use those values in my destructuring pattern. Speaking of that destructuring pattern, we want that to go here, and our destructuring pattern needs to account for the topic. And it defaults the JavaScript and the format which defaults to Live.

[00:00:44]
And also a slides object which has a start that defaults to 0 and an end of it defaults to 100.
>> Kyle Simpson: So that is as breaking down which means we end up creating four variables, the topic variable, the format variable, and then start an end. And then all we should need to do is restructure those back together so we will add topic and format back in and then we will add a slides object that includes start and end.

[00:01:34]
>> Kyle Simpson: Now if you wanted to be able to pass along any properties that you hadn't otherwise already accounted for, you could use the object gather and say ...otherProperties. And then you would simply do an object spread by saying, ...otherProps,
>> Kyle Simpson: It's not needed for this particular example but just to give you an idea of how your destructuring pattern can include anything else that might have been passed along.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now