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

First prompt example

Why did the code run when he saved it the first time? Shouldn't it have returned a syntax error because he didn't close it with a semicolon?

1 Answer

Zac Mackey
Zac Mackey
11,392 Points

Technically he should use a semi-colon after the function call, but since it was the ONLY function being called on the page it wasn't exactly necessary. Semi-colons are statement separators. That means if he had ANOTHER statement following the one he left the semi-colon off, he would have most likely ran into a syntax, or other, error.

Here's a pretty decent example

prompt('hello')  alert('yo');

If you run this code you'll encounter a Syntax error because there is no semi-colon after the prompt function. i.e. there is nothing to separate these two function calls.

However, if you run this code:

prompt('hello');alert('yo');

With no spaces between the two functions you'll still achieve the desired results of a prompt, followed by the alert.

Best rule of thumb is to just use semi-colons, period.

Sick! Thanks man