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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 1

Sean Flanagan
Sean Flanagan
33,235 Points

Build an Object Challenge Part 1: my solution

Hi guys and girls.

How does my solution look?

https://w.trhou.se/cfob1phx7n

As ever, constructive feedback is appreciated.

Cheers

Sean

3 Answers

Joel Bardsley
Joel Bardsley
31,249 Points

Looks great, Sean!

Something that might come in handy for future reference is the use of Trailing commas for when you're writing more complicated code. An example would be code that adds new properties to object literals - you wouldn't want to write extra code that adds a comma to the previous property just so you could add a new one without resulting in a syntax error.

The link I've provided goes into good detail of when you can and cannot make use of this technique.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Joel.

Thanks for your help. I've given your comment an upvote and Best Answer.

Sean

Amber Chieffe
Amber Chieffe
4,347 Points

If JSON disallows trailing commas, and JavaScript doesn't need them, what is the benefit of using them? It seems to me that it would be a better practice to simply add a comma at the beginning of any property that you add to an existing array. I know that seems weird from a human perspective, but wouldn't it make for fewer errors down the road?

Thanks for any clarification on this! I promise I'm not trying to be combative - I am really curious why programmers choose the practices that they do.