Local Scope and
Global Scope. A global variable has global scope and a local variable has local scope. A Global variable is declared outside of any function whereas local variable is declared inside of a function.
A Global variable can be accessed from outside of the function as well as inside of the function but, a local variable can only be accessed only inside of the function. If accessed from outside of the function, you will get ‘undefined variable’ error.
var foo = 50; //
More Advanced Example
First of all, getaverage function is called passing two variables which return average value of passed variable. Then, the return value is stored in myResult variable which is a glovbal variable. After this, logResult() function is called which displays the value stored in global variable.