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 trialBaran Ureten
5,749 Pointsincrement
is it possible to use i++ instead of i+=1 ??
does javascript accept increments such as "++i" or "i++" ?
edit: so, do both pre and post increments exist in javascript?
3 Answers
Shawn Boyd
14,345 PointsAlthough it's hard to find concise documentation on this, you can see that both pre- and post-incrementation work by testing them out. Pop open your Chrome DevTools console and run something like this line by line.
test = 0 (returns 0)
test++ (returns 0)
test (returns 1)
++test (returns 2)
test (returns 2)
David Lacedonia
13,627 PointsYes, it is possible.
You can do...
number++;
and number will increment by 1
Gavin Murphy
10,004 PointsYes it is certainly possible to use either i++ or i += 1. As far as i know you can also use ++i but the proper convention is i++. I hope this helped.
:-)
Baran Ureten
5,749 PointsBaran Ureten
5,749 Pointsthanks!