f1();
console.log(c);
console.log(b);
console.log(a);
function f1() {
var a = b = c = 9;
console.log(a);
console.log(b);
console.log(c);
}
代码实际执行顺序如下:
function f1() {
var a;
a = 9;
b = 9;//因为b没有声明,所以是全局变量
c = 9;//因为c没有声明,所以是全局变量
console.log(a);
console.log(b);
console.log(c);
}
f1();
console.log(c);
console.log(b);
console.log(a);
最后输出:9;9;9;9;9;a is not defined
//如果要一起声明,应该
var a = 9,b = 9,c = 9;