With regard to scope, we must distinguish four kinds of variable:
Top-level entities are script properties declared, and script objects and handlers defined, at the top level of a script or script object. (See "Top-Level Entities" in Chapter 8.)
An explicit local is a variable announced by a local declaration , which looks like this:
An explicit global is a variable announced by a global declaration, which looks like this:
A undeclared variable is none of the above. It's just a name that your code suddenly starts using. This is legal, but when you do it, AppleScript assigns the variable a scope , in ways that may surprise you.
The scope of a variable, and what kind of variable it is (these amount to the same thing), are determined at compile time .