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

Why are commands in console used without semicolon?

Hi there, just a quick question that came up while I was watching the video. Dave uses different commands in the console to add and remove numbers from an array, as well as print out the array. He doesn't add a semicolon after nums.shift() etc. Why is that?

1 Answer

Steven Parker
Steven Parker
243,173 Points

For writing code, using semicolons at the end of statements is a "best practice". But unless "strict" mode is being used, they are optional unless another statement begins on the same line.

Since console commands are temporary and generally entered one at a time, it's convenient to omit the semicolon.

Hi Steven Parker, that makes sense! Thank you. :)