Shorthand Properties in ES6

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet
Published 8 years ago
Updated 3 years ago

Shorthand properties allow you to compose complex objects from other objects.

John Lindquist: [00:02] Where destructuring in ES6 allows you to easily get properties out of an object, this shorthand property syntax allows you to easily push properties in. It's like destructuring backwards.

[00:11] If I have a first name and a last name and I want to create a person, I can just say, "firstName, lastName." Then when I log out my person and I run this, you can see that it logs out an object with the first name of John and a last name of Lindquist.

[00:29] If I wanted to build some more objects, like I want to build a team. I have a mascot with a Moose, and I wanted to build a team like this, where I have a person and a mascot, and then I log out my team. I have a team object with a person of "firstName, lastName," John and Lindquist, with the mascot of moose.

[00:53] This syntax allows you to easily construct objects with the properties and things you already have and just build them up however you'd like.

Michal
Michal
~ 6 years ago

I think the lesson 9: Destructuring assignment in ES6 should come just before this one, because you mention destructuring in the video, and it is confusing for those who watch it in order.

Raunaq Sahni
Raunaq Sahni
~ 5 years ago

Precisely. This vid doesn't have any other dependencies.