A globally-scoped variablevar a = 1;// 全局变量function one() { alert(a); // alerts '1'}局部变量var a = 1;function two(a) { alert(a); // alert出 形参 a 的 实参,而不是全局变量 a 的值'1'}// 本地变量function three() { var a = 3; alert(a); // alerts 本地的 a 的值'3'}Intermediate: JavaScript 没有类似的块级作用域(ES5; ES6 引入 let)var a = 1;function four() { if (true) { var a = 4; } alert(a); // alerts '4', 而不是全局变量 a 的值 '1'}Intermediate: Object properties对象的属性--var a = 1;function five() { this.a = 5;}alert(new five().a); // alerts '5'Advanced: Closurevar a = 1;var six = (function() { var a = 6; return function() { // JavaScript "closure" means I have access to 'a' in here, // because it is defined in the function in which I was defined. //闭包访问上级函数中的变量, alert(a); // alerts '6' };})();Advanced: Prototype-based scope resolution基于原型的作用域http://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript--这个没法写了,出处如上,但感觉这个基于原型的案例看着很别扭,、就实践了一下,果然有问题。