» Language: Scope

Scope is the context in which variables are created and accessed. If a variable exists in a parent scope, it is accessed and can be modified. Otherwise, the variable is created in your current scope.

Scopes are created with blocks. A block is a possibly empty sequence of statements within matching brace brackets {}. You may nest blocks to create nested scopes.

In addition to explicitly created blocks, there are implicit blocks:

  1. The policy block encapsulates an entire policy.
  2. Each any, all, and for statement is considered to be in its own block. Note that if statements do not create their own block.

The example policy below shows various effects of scopes:

a = 1
print(a) // 1

f = func() {
    print(a) // 1
    a = 12
    b = 1
    return undefined
}
f()

print(a) // 12
print(b) // undefined