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 Multiple Items with Arrays Using For Loops with Arrays

Ricardo Garcia
Ricardo Garcia
5,939 Points

Whats the difference between i++ and i += 1 in this context

for(var i = 0; i < list.length; i++);
for(var i = 0; i < list.length; i += 1);

2 Answers

Hi Ricardo,

In the context you gave, both actions would just increment variable i by one.

Both are a type of shorthand, both would be legal.. i++ would be seen more often, though.

Take care! -- Cal

KHOA NGUYEN
KHOA NGUYEN
4,061 Points

i think i++ means: i will be increased by 1 AFTER all the statements inside the for loop executed (for a round). It might be significant in a case where you have a conditional statement to break the loop when i reaches a desired value.