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

At 5:30, there is a semicolon missing after closePath(). How is possible that the code works anyway?

Hello, how is possible that this code works:

context.lineTo(10, 20);
context.closePath()
context.stroke();

But when I put

alert("a") alert("b");

to console, it produces error?

Thanks, Peter

1 Answer

Iago Wandalsen Prates
Iago Wandalsen Prates
21,699 Points

If you want to go deep into it, I recommend reading http://inimino.org/~inimino/blog/javascript_semicolons

But long history short, "Firstly, a semicolon is optional only where there is a line break, a closing brace, or the end of the program. Semicolons are not optional between statements appearing on the same line. Additionally, a semicolon is not implied at the end of a line if the first token of the subsequent line can be parsed as part of the same statement."

alert("a") alert("b"); falls into not optional time.