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 Building Applications with React and Redux Actions, Dispatch, and Reducers. Oh my! Actions and Action Creators

Qian Chen
Qian Chen
33,579 Points

ES6 syntax?

Is this ES6 new syntax? Need more explanation:

{
  type: '...',
  index,
  score
}

1 Answer

andren
andren
28,526 Points

Yes it is indeed. In ES6 if a property shares the name of a variable it will automatically be set equal to the contents of that variable without you having to specify a value.

So the code you quote is equivalent to this code:

{
  type: '...',
  index: index,
  score: score
}

Where index and score are variables that have been defined earlier in the code.

So it is just a short way of setting the properties equal to a variable that is named the exact same thing as the property.

David Axelrod
David Axelrod
36,073 Points

I was wondering the same thing!! Thank you!