Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,340 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