There are regions in the source code where you can refer to variables without getting access errors. This can be best understood without even running code. As it only concerns areas of code where different variable names have meaning.
A variable added here is in the global scope and therefore accessed from anywhere in the whole program.
After defining a variable in the lexical scope, you can reference to that variable anywhere in the lexical scope.