Scoping refers to the availability of a variable within a function and a contract in Solidity. Solidity provides the following two locations where variables can be declared:
- Contract-level global variables—also known as state variables
- Function-level local variables
It is quite easy to understand function-level local variables. They are only available anywhere within a function and not outside.
Contract-level global variables are variables that are available to all functions including constructor, fallback, and modifiers within a contract. Contract-level global variables can have a visibility modifier attached to them. It is important to understand that state data can be viewed across the entire network irrespective of the visibility modifier. The following state variables can only be modified using functions:
- public: These state variables are accessible...