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 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,558 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!