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

Dave's mistake?

In the "for" loop, Dave adds +=1 to the i variable, but doesnt put semi-colon at the end of it, yet it still runs. Shouldn't he put semi-colons?

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Damjan,

While the current convention is to use semicolons, with JavaScript, semicolons are actually not always required. Semicolons are statement separators. In a for loop, yes they would be needed for the first two, because they are on the same line and need to be separated, but the parser will automatically insert a semicolon at the end of the line.

There is quite the debate going on about whether the convention should be pro semicolon or no semicolons. If you want to read up more on this debate, just Google Search "semicolon in JavaScript" for many, many articles and posts.

So, in short, no Dave is not incorrect.

Keep Coding! :) :dizzy:

Marcin Jerwan
Marcin Jerwan
4,628 Points

in the "For Loops" video, at 03:06 mark, top condition is counter<10, and at the bottom example counter<=10 . is this a simple mistake or is it meaningful?