A globally-scoped VariablevarA = 1;//Global VariablesfunctionOne () {alert (a);//Alerts ' 1 '} Local VariablesvarA = 1;function(a) {alert (a);//alert out parameter A's argument, not global variable A's value ' 1 '}//Local Variablesfunctionthree () {varA = 3; alert (a); //Alerts local A's value ' 3 '}intermediate:javascript does not have a similar block-level scope (ES5; ES6 introduction Let)varA = 1;functionFour () {if(true) { varA = 4; } alert (a); //Alerts ' 4 ', not the value of global variable a ' 1 'properties of the}intermediate:object Property object--varA = 1;functionFive () { This. A = 5;} Alert (NewFive (). a);//Alerts ' 5 'advanced:closurevarA = 1;varSix = (function() { varA = 6; return function() { //JavaScript "Closure" means I had access to ' a ' //because it is defined in the function in which I was defined. //closures Access variables in the parent function,alert (a);//Alerts ' 6 ' };}) (); Advanced:prototype-based scope resolution based on the scope of the prototype http://Stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript--This can not write, source as above, but feel this prototype-based case looked very awkward, and practice a bit, sure enough there is a problem.
Scope of the variable