Global Variables
Learn all about Global Variables in this comprehensive tutorial.
- •Variables that are created outside of a function (as in all of the examples in the previous pages) are known as global variables.
- •Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function.
Global Variables
Variables that are created outside of a function (as in all of the examples in the previous pages) are known as global variables.
Global variables can be used by everyone, both inside of functions and outside.
If you create a variable with the same name inside a function, this variable will be local, and can only be used inside the function. The global variable with the same name will remain as it was, global and with the original value.
The global Keyword
Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function.
To create a global variable inside a function, you can use the global keyword.
Also, use the global keyword if you want to change a global variable inside a function.
Module quiz
2 questionsWhich of the following is true about Global Variables?
What is the most common pitfall when working with Global Variables?
Answer all questions to submit.