Kyle spends a few minutes talking about a technique for dumping variables through destructuring. He uses empty slots in an array to “catch” the variables to be dumped. He then uses the gather operator to populate the original variable with the remaining destructured values.
- So, if we know that we can receive…assignments without declaration,…we can also do an interesting little trick,…this is just a little side note,…it's not something I do an awful lot…but remember earlier when we were talking about…using block scoping to do that whole X swapping thing?…Remember we did let tmp equals X,…X equals Y,…Y equals tmp.…Remember that?…We can use array destructuring…to do the swapping.…
Let's say I had an X…that was 10…and a Y that was 20…and I wanted to swap the two?…Could do that whole block thing that I just showed…or what I could do is say an array destructuring…with X and Y as my pattern…should be destructured from an array…that has them in the opposite order.…
And of course that's not limited to two.…You could do as many of those as you wanted to, right?…While we're on the topic…of using this array destructuring stuff,…if we had an A that was an array like that,…we could say for example.…
So, now we're making an array, a composite array,…I'll use spaces just to make this a little more readable.…
This course was created by Frontend Masters. It was originally released on 01/10/2017. We're pleased to host this training in our library.
- The arrow function
- Arrow function variations
- Closures and explicit blocks
- Default values
- Using the gather and spread operators
- Dumping variables
- Concise properties and methods
- Symbols, iterators, and generators
- Optimizing codes for the reader
Skill Level Intermediate
1. Arrow Functions
2. Block Scope
3. Default Values and the Gather/Spread Operators
5. Template Strings
6. Symbols, Iterators, and Generators
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.