Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React by Example Building the Application Changing Guest Name in State

Philip Kroupoderov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Philip Kroupoderov
Front End Web Development Techdegree Graduate 21,641 Points

What is that shortcut??

He typed a shortcut when he just typed in name within the setName function, right after ...guest. Can somebody please explain what kind of shortcut that is??????

2 Answers

Kristina Burge
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Kristina Burge
Front End Web Development Techdegree Graduate 20,341 Points

He's referring to the Object Property Shorthand in ES6. Sitepoint has a nice article to reference.

If the property name and key name are the same in an object literal, you can write it with the shorthand notation.

That's why you can do:

const obj = {
    name
};

instead of

const obj = {
   name: name
};

I hope this helps!

{...guest// clones guest obj at index, name // same as saying name:name} since key and value are the same in ES6 you can simply set name