1 2 3
One thing to note here is that if you create the variable in the global space (i.e. outside of a function scope) then it will be global. If this code is run inside a function then the variable created will be local to that function.
1 2 3
This variable will always be global, no matter where it is created.
Give it a go by running the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
So, bottom line? It's good practice to define your variables local (as in 'var variable;') so that they don't clobber anything else within the scope. Doing this as a matter of course prevents any future code breaks from global variables.