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 trialQian Chen
33,579 PointsES6 syntax?
Is this ES6 new syntax? Need more explanation:
{
type: '...',
index,
score
}
1 Answer
andren
28,558 PointsYes 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.
Qian Chen
33,579 PointsQian Chen
33,579 PointsThank you.
David Axelrod
36,073 PointsDavid Axelrod
36,073 PointsI was wondering the same thing!! Thank you!