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 trialDarian Wilkin
3,568 PointsWhy 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
7,954 PointsI 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?
Erik Nuber
20,629 PointsI 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.
john larson
16,594 Pointsjohn larson
16,594 PointsThat seems like a very believable answer Emily.