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

How come in the javascript console you type Math.round(2.2) without a semicolon at the end?

Math objects

1 Answer

andren
andren
28,521 Points

The instructor likely just forgot to include it. In JavaScript (unlike languages like C++, Java or C#) semicolons are not actually mandatory. They are only strictly required if you want to have multiple statements placed on the same line. If you don't have multiple statements on one line then not including a semicolon is completely accepted by JavaScript.

However always using semicolons is considered a standard and good practice. On the console it doesn't really matter since the code isn't going to be saved anywhere anyway, but when writing scripts you should include them.