The scope of a Global Variable is global, and it can be accessed from anywhere in the programme. At every point in the programme, assigning to global variables has global consequences.
Local Variables: The name of a local variable must begin with a lowercase letter (a-z) or an underscore ( ). These variables are only available inside the scope of the code construct in which they are declared. A local variable can only be accessed within the initialization section. Outside of the method, local variables are not accessible.
Within a class, it's used to declare variables. There are two sorts of variables: class variables and instance variables. Class variables have the same value across all instances of the class (i.e. static variables), while instance variables have different values for each object instance.
A global variable in computer programming is a variable with global scope, which means it is visible (and thus accessible) throughout the programme unless shadowed. The global environment, also known as the global state, is the collection of all global variables.
Global variables are created and utilised in the same way that other variables are. Simply give them a value and start using them to define them. However, assigning to global variables from any point in the programme has global implications, as their name implies.