Local variables are created when a function starts, and deleted when the function is completed.
A variable that is declared outside of a function definition is called a Global Variable and it has global scope, all scripts and functions on a web page can access it and modify throughout the program.
Here a Global Variable declared as total. Then add values to the total inside a local function addValue(). Next, dispValue() function display the value of total. Here you can see the global variable value modify inside a local function and the new value is displayed in another local function. It happens because of the scope of Global Variable.
If a variable is assigned a value without first being declared with the var keyword, it is automatically added to the global context and it is thus a global variable:
Here you can see, the variable total is not declared. Inside the addValue() function variable total assigned a value. So, its scope is global because its not declared.