How can I reach some variable declared in another place from within an external javascript file ?
Suppose in an html file I have the following
The script can just assume that those variables will be set. They must be because they are needed. The script can check if they are undefined and fail gracefully (do nothing) when they are not. The variables are not in another namespace.
It doesn't matter.
All <script>
blocks in the page share the same context and variables.
when a variable is defined without var
it is said to exist in global scope. When your JS is loaded into your page, it is aware of any variables that exist globally at that time. So, what google is doing is defining some variables and then loading in an external script.