Scope is where a variable can be used. A variable can often be used inside a function, a
Sometimes a variable can be used everywhere in the program, a
There are also cases in which a variable only exists inside an statement or loop. These are also
x below is a local variable, it can only be used inside the
If you move the variable x outside of the function, it becomes a global variable.
Global variables can be used by multiple functions. In this example
Global variables are sometimes considered a bad practice.
When possible, you should pass variables as function parameters instead.
- What’s the difference between a local and global variable?
- How can you make a global variable?