function foo() {
let a = b = 0;
a++;
return a;
}
foo();
typeof a;
typeof b;
複製程式碼
解析:函式foo內宣告變數a = window.b,全域性變數b = 0;所以函式外列印區域性變數a為undefined,全域性變數b為number
function foo() {
let a = b = 0;
a++;
return a;
}
foo();
typeof a;
typeof b;
複製程式碼
解析:函式foo內宣告變數a = window.b,全域性變數b = 0;所以函式外列印區域性變數a為undefined,全域性變數b為number