Below is the list of topic that is covered in this article:
· Introduction to Scope.
· What is the scope.
So let’s see each and every topic one by one.
What is Scope?
In simple words, scope determines the accessibility or visibility of variables, objects, and functions from different parts of code.
1) Local scope
2) Global scope
Local Scope: As the name suggests, the scope of the variable is limited to that particular function,means the variable cannot be accessed outside the function.
This gives an advantage as the same name can be used in different functions as the variables are bind with the function.
Global Scope: As the name suggests, the scope of a variable is not limited to one function, any function in the code can access the variable.
A variable is in the global scope if defined outside the function.
The scope is a policy that manages the availability of variables. A variable defined inside scope is accessible only within that scope, but inaccessible outside.