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 triallevikordus
4,877 PointsI noticed sometimes don't use ; in console commands, is this because it will execute right after pressing enter?
I assume thats why, but i'm not sure why sometimes you use ; at the end of console commands. I thought all lines needed to end with ;
Am i correct in assuming that since it is executed one line at a time in the console you dont need the ;?
1 Answer
Steven Parker
231,275 PointsActually, you don't need a semicolon at the end of any line. A semicolon is only necessary to separate statements that are on the same line.
However, it is commonly considered a "best practice" to put a semicolon at the end of every statement, regardless if it is the last one on the line or not.
Aaron Martone
3,290 PointsAaron Martone
3,290 PointsJS implicitly provides automatic semi-colon insertion where it feels the statement naturally ends, however, as Steven Parker noted, it is a much better practice for you to explicitly inform the interpreter where your commands end to avoid ambiguity. Also, be aware that console is not JavaScript, but actually a part of the Browser interface. For example, Node.js, server-side JavaScript, has no concept of 'console'. It is something that only exists to the browser to send data to its console.