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 Basics (Retired) Storing and Tracking Information with Variables Capturing Visitor Input

Austin Cascarelli
Austin Cascarelli
3,522 Points

Why is it that the prompt function doesn't require a semicolon?

Is prompt("What is your name?") considered to be a statement?

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Austin,

Semicolons aren't actually required in JavaScript. Unlike some other languages (i.e. Java), semicolons in JavaScript are just statement separators. At run time, the interpreter automatically adds the semicolons at the end of each statement / line. So, no that line would not require a semicolon, but "best practices" would say (although that is still being argued quite heavily among many coders) that there should be a semicolon there.

The only time semicolons are needed would be if you have multiple statements on the same line (i.e. the for loop conditionals).

As you progress and delve more into JavaScript, you will probably see both. It is important though that you stay consistent and/or follow the stylesheet with whom you are working.

Hope that answers your question. :) :dizzy:

Austin Cascarelli
Austin Cascarelli
3,522 Points

That did answer my question! Thanks, Jason