- Local variables
- Global variables
Local variables are the variables that are introduced within a function or a block of code or a scope which is undefined for the rest of the code. It means the only specific block of code knows that variable but is unknown for rest of the code.
A daily life Example:
y=”I love pakistan”
myFunction() //calling the function
Variables that are accessible at any point or line of code is called global variable. Global variables are declared outside the block of scope and is easily accessible at any point. Global variable is easily and usually visible throughout the program unless it is shadowed.
Real world example:
Let suppose Home A and home B are neighbors to each other. A and B has to go to shop always to buy something for their home or self use. For their ease, A and B decided to construct a small road which they can easily use to go to a shop. They decided and constructed the road instead of constructing it locally from their home or else. Now, A and B and as well as all those who belong to the premises or who will buy a home next or beside to A and B and wish to use this road to go to shop can use it will use it thus that would be considered as a global variable.
- Primitive Datatype
- Composite Datatype
- Special Datatype
Buy on amazon with upto 40% off