June
27th,
2017
Variables declared within a JavaScript function, become LOCAL to the function.
Local variables have local scope: They can only be accessed within the function.
A variable declared outside a function, becomes GLOBAL.
A global variable has global scope: All scripts and functions on a web page can access it.
Automatically Global
If you assign a value to a variable that has not been declared, it will automatically become a GLOBAL variable.
Do NOT create global variables unless you intend to. In “Strict Mode” automatically global variables will fail.
In HTML, the global scope is the window object. All global variables belong to the window object.