Destructuring Assignment in ES6

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet

ECMAscript 6 destructuring provides flexible options for variable assignment.

Dipankar
Dipankar
~ 5 years ago

Destructuring is a shortcut syntax. Assignment of Skyler to Skyler object forced me to rewind.

Zhenyang Hua
Zhenyang Hua
~ 5 years ago

Is destructuring often used in modules import ? e.g. import { XX } from 'xxx/core' ?

Stephan Maier-Knodt
Stephan Maier-Knodt
~ 5 years ago

Hi, it is a pity that you mix old ECMA 5 and ECMA 6 script together in every session of the course "Learn ES6 (ECMAScript 2015)". So it would be nice to just use "let" instead of "var" always. And for sure some the other stuff you very nicely introduce. So would would have a much better learning effect.

But I love your way of introducing things in short videos.

Jesse
Jesse
~ 5 years ago

At about the two minute mark, when you use state:location the state becomes part of your url on reload. The page returns a file not found error as es6/index.html becomes es6/New%20York. So location is a keyword to be avoided.

Gene
Gene
~ 4 years ago

Code in transcript is wrong.

var [,Skyler] = people;

Should be:

var [Skyler,] = people;

Mike
Mike
~ 4 years ago

Great examples. Your videos are one of the reasons I subscribe to Egghead.

Lluís Peinado
Lluís Peinado
~ 3 years ago

Hi, I am playing around with the examples. Just wanted to add a second parameter to the arrow function inside like:

people.forEach(({firstName},{lastName}) => {
  console.log(firstName) || displayInPreview(firstName);
  console.log("lastName",lastName || displayInPreview(lastName));
})

But I get undefined for the lastName. Any ideas to display there other parameters? Thanks!

Hans Brough
Hans Brough
~ 10 months ago

I like the Skyler example at the end as it combines a few concepts - the downside of course is it assumes the order of objects in the array won't change. For that reason I'd just use .find() and then perhaps de-structure the response as needed.