Originally posted by Andy Hahn:
So is it true that I do not have to use the "var" keyword if I want to declare a variable only at the global level?
Essentially, but it is considered poor practice.
At global level, whether you use the
var keyword to declare a variable, or cause it to be automatically created by assigning a value to a previously undeclared variable, it still ends up as a property on the window object.
Not declaring the variable is sloppy and I'd avoid it.