Kinds of Variable
With regard to scope, we must distinguish four kinds of variable:
- Top-level entities
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.)
- Explicit locals
An explicit local is a variable announced by a local declaration , which looks like this:
local x
- Explicit globals
An explicit global is a variable announced by a global declaration, which looks like this:
global x
- Undeclared variables
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 .
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access