Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.