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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 2 Solution

tzehuilee
tzehuilee
19,911 Points

Why is there no "var" declaration for the html variable? Missing end semicolon.

I noticed in the video of all the variables declared, the variable html is the only one never declare with var. How come? Also at the snippet of the code: html = "You got " + correctAnswers + " question(s) right." There is no semicolon after that part of the code. What's interesting it still run not only on workspace but also on my Netbeans IDE.

2 Answers

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

var and semicolon are best practices, but often a JS file will run without them. Still always better to use "var" and "semi-colons" when you should. In some cases it can probably make your program run more smoothly, plus it can make the code more readable.

Samy Basset
Samy Basset
11,862 Points

With var you can also declare the scope. you can see declared variables with var as a local scope, and declared variables without var as a global scope. All though it is recommended to always use the var statement.