HTBasic supports Local and Global and STATIC variables.
By default, all variables are local in scope unless included in a COM statement which makes them global. Global means they can be shared in "common" between contexts. A program "context" refers to the main program, or a callable SUB or FN (function). The values of variables are "local" to, and only accessible within, the context in which they are defined. So, a SUB, for example, has its own set of variables which can even have the same names as variables in other contexts outside the SUB without affecting them. All local variables are assigned the value zero when the context begins execution. When the context finishes execution, the values of the local variables are discarded. When a context is called recursively, each invocation of the context is given its own set of local variables.
STATIC is only used inside SUBs and FNs to declare variables that should retain their values between calls. Since the main program only runs once, it doesn't need to use STATIC.
DIM, INTEGER, LONG, REAL, COMPLEX, STATIC, and ALLOCATE are used to declare local variables.
ALLOCATE reserves memory for array and string variables. DEALLOCATE releases the memory before the context finishes execution.
COM defines a "block" of one or more variables that that are shared in "common" globally (between contexts). Each COM block is uniquely identified with a name (although one block is allowed to be nameless). Each context can have as many COM statements as needed.
To access COM variables, a context must include a COM statement that identifies the COM block and gives the names by which the variables will be known in that context. Thus, each context can give a different name to the same COM variable. COM variables are hidden from all contexts that do not include a related COM statement.
When a new program is brought into memory, the existing COM blocks are compared to the COM blocks defined in the new program. Any COM blocks that exactly match are retained and their data values are available for use by the new program. Any COM blocks that do not match are deleted and the memory used by their data values is released and may be reused by the new program.