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 Foundations Strings Basics

Statement Terminator Using Semicolon

I just realised that in this particular video that the semicolon was not added to the end of the var. I tried the same with console and other commands and it seemed to work just fine. In Java for instance the code will give an error if the semicolon is missing (I realise they are completely different). Is omitting the semicolon a good practice? Does it later affect the code in anyway? Since it seems to be executing anyways.


1 Answer

Christopher Hall
Christopher Hall
9,052 Points

You're right that adding semicolons at the end of statements in Javascript is not required for the code to run properly. It is a good practice to add them however, since it makes the code clearer and more maintainable. Also if you minify Javascript code for production servers, omitting semicolons can cause syntax errors in some cases that were not there before minification.