代码如下:
var scope = "global";
function f( ) {
alert(scope); // Displays "undefined", not "global"
var scope = "local"; // Variable initialized here, but defined everywhere
alert(scope); // Displays "local"
}
f( );
不是很明白为什么第一个alert没有打印全局变量。
※ 来源:·水木社区 newsmth.net·[FROM: 117.79.73.*]
FROM 117.79.73.*