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 Basics (retired) Stateful Components Creating a Component Class

Weird syntax (React.js)

Why does Jim put a comma on the last element of an object? Also, why doesn't it cause errors?

Thanks in advance! ~Alex

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I've seen others do this as well, and no it doesn't cause an error. But I believe the reason to do it is to easily allow yourself to quickly add a new property or method to an object without introducing a syntax error. This way you don't have to remember to add a comma to your last thing in the object before you start typing the new one. I'm fairly sure Alena does it in one of her PHP courses as well, but can't find it right now. Hope this helps! :sparkles:

Thank you for explaining! :)

Francis N
Francis N
10,376 Points

Yes I kind of like that you can add/keep the commas there without throwing an error like you usually would see happen in ES5. Although, I was a little confused for a second at first because it wasn't mentioned in the video.