Variables are usable only within a limited scope. A scope is the code hierarchy in which a variable is declared. Each variable can be used within its own scope, as well as in other specific scopes that also fall within the declared scope.
Following are the main types of scopes for variables:
Global variable: refers to any variable declared outside of all templates. Global variables can be referenced anywhere within the script.
Template variable: refers to variables defined within templates, such as the main template, and have a local scope and are scoped by the containing scope.