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 Data Using Objects Mixing and Matching Arrays and Objects

why dont we get an error with the html variable

at line 34 dave uses an html variable. but he never created a variable name html. why does that work?

1 Answer

It is possible to create a variable without using var, const or let. It comes down to scope.

If a var, const or let keyword is not used before a variable name, then that variable's scope is GLOBAL .

Variables declared outside a function become GLOBAL, and all scripts and functions can access it and unless you declare it as const, can overwrite it .

If you declare a variable without using var, const or let, the variable always becomes GLOBAL regardless of whether or not it has been declared within a function or not.