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
Matt Bloomer
10,608 Pointsiterating-loops with arrays
I am in the Javascript loops, arrays and objects section, loops with arrays. One of the answers to the challenge was to use a ++. I went back and watched the video and didn't see him use that bit of code; can someone please tell me what that means and when I should use it?
2 Answers
Marcus Parsons
15,719 PointsHi Matt,
A ++ is an incremental operator that increments a variable by 1. You can either prepend or append the ++ to a variable/number. You'll notice a difference, though, if you are outputting the value while incrementing. For example,
var a = 5;
console.log(a++); //outputs current value of a (5) and then a increases by 1 which becomes 6
//a is now 6
console.log(++a); //a increases by 1 becoming 7 and then outputs the value of a, which is 7
//output:
//5
//7
Both types are used depending on what you need to code and how you need to code.
Jacob Mishkin
23,118 Points++ is the same as +=1
its just a different style. that's all.