This code example will declare a global variable carName, even if the value is assigned inside a function.
myFunction();
// code here can use carName
function myFunction() {
carName = "Volvo";
}
Do NOT create global variables unless you intend to.
In "Strict Mode" automatically global variables will fail.
With JavaScript, the global scope is the complete JavaScript environment.
In HTML, the global scope is the window object. All global variables belong to the window object.
http://www.w3schools.com/js/js_scope.asp
No comments:
Post a Comment