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 Simplify Repetitive Tasks with Loops For Loops

Why not ++?

The ++ operator is much simpler than += and works in Javascript, I was hoping to get some clarification on why the instructor in this video is still using +=, particularly in a for loop where ++ is the norm afaik.

I've noticed it before but figured it would be taught at some point, I was just curious if there was a particular reason it wasn't being used.

2 Answers

Emily Carey
Emily Carey
7,954 Points

I would use ++ to increase by 1 and += if you need to increase by more than 1 or if adding on to strings or objects etc.

Maybe they're doing it in your course to make it more explicitly clear?

That seems like a very believable answer Emily.

Erik Nuber
Erik Nuber
20,629 Points

I am not sure which is actually the norm but, I believe this is taught at some point. I certainly use the ++ when at all possible inside for loops and outside on some occasions.