Local and Global Scope
• Local scope
• Variables that exist in local scope are called local variables
• Parameters and variables that are assigned in a called function
• Global scope
• Variables that are assigned outside all functions
• Variables that exist in this scope are called global variables
• A scope is like a container
• When a scope is destroyed all the variables inside it are forgotten
• There is only one global scope and it is created when a program starts
• When a program terminates, this scope is destroyed
• A local scope is created whenever a function is called
• All the variables assigned exist within this scope.
• When the function returns, the scope is destroyed.
16