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 trialtzehuilee
19,911 PointsWhy 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
Treehouse Guest Teachervar 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
11,862 PointsWith 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.