Check out a free preview of the full JavaScript: From Fundamentals to Functional JS, v2 course:
The "Destructuring Solution" Lesson is part of the full, JavaScript: From Fundamentals to Functional JS, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Bianca walks through the destructuring solution.

Get Unlimited Access Now

Transcript from the "Destructuring Solution" Lesson

[00:00:00]
>> So what do we think is gonna happen? How about with the Diet Coke?
>> What do we think is gonna happen?
>> Well, it looks like the object at the top, does it have the name object It does okay.
>> No, it doesn't, it's just an anonymus object.

[00:00:27]
>> Okay, so then this should, Just [INAUDIBLE]
>> [INAUDIBLE] How can we fix it?
>> [COUGH] [LAUGH] Well, if we were writting it with destructuing we have, const, open bracket, name, room, weapon equals. Okay, name and weapon, okay, and then the name on the right side name, call in rusty.

[00:01:07]
>> Like this?
>> Yeah, pretty much, And then yeah, looks over missing the room in the first on the left side but.
>> Okay.
>> [COUGH]
>> All right, cool. What do we think, is it gonna run?
>> It will run.
>> Is it gonna give us what we expect?

[00:01:34]
>> Well, so I mean, after you ran that, then you could just call name and it would give you Rusty, I think, for example. I don't know if that answers your question, but that's me.
>> Yeah?
>> Yeah.
>> Do snap or something [SOUND] Awesome, so do you guys use destructuring in your day to day life, do you guys use ES6 in your work?

[00:02:01] A little bit, so I use ES6 I don't use it, I sometimes use it, okay, most of the stuff, cool, all right?
>> I have a question.
>> Yeah.
>> So, we talked a little bit about this, you're both kind of thrown on how, so like when you're calling name right now, I guess it's like an anonymous object.

[00:02:26] It doesn't have like an explicit name, so when we call the variable name is it calling on like a global object or something, does that make sense?
>> So it's actually create, it's basically saying var name equals, well, let's name our object really quick, let's just name this object.

[00:02:46]
>> [COUGH]
>> Right, so it's the equivalent of saying var name or const name actually, but, I wanna go back this object name.
>> Okay.
>> So, you're declaring a variable Yeah. And you're doing that three times, so this is saving you three lines of code, maybe yeah, about three to do it this way.