ES6 destructuring allows developers to specify default values for each element they are extracting. Kyle demonstrates how to declare default values both for the individual variable as well as the entire destructured object.
(bright music)…- Now, it might be the case that I would like,…in the case where, for example,…I don't get anything back for b,…I might like to apply a default value.…If I were doing that over here, what would I end up doing?…I would end up saying something like,…tmp of one, not equal to undefined,…tmp of one or,…and then give it a default value like 42, right?…So now imagine all of that craziness…added in with all of that undefined checking stuff…that we'd be doing.…
And you can probably quickly imagine…how Crazy Harry that does,…cause you've also probably written code like that before.…I certainly have.…Cause I've needed to do this kind of stuff,…on more than one occasion, many occasions.…Okay?…Here's how simple it is with destructuring.…We simply say, the default value for b should be 42.…And that default assignment is going to behave…exactly the same as the parameter defaults…that we already went over.…Have all the same, it's a lazy expression,…you can do stuff in that just like you can elsewhere,…including the required call,…
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?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
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.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.