Day 6:湯姆克魯斯與唐家霸王槍——變數的作用域(Scope) (2)
星爺強碰阿湯哥誰會贏?Global Scope vs. Function Scope
function myFunc(){
var n1 = "Stephen Chow";
console.log("myFunc(): n1=", n1);
console.log("myFunc(): this.n1=", this.n1);
console.log("myFunc(): window.n1=", window.n1);
}
var n1 = "Tom Cruise";
myFunc();
console.log("Global: n1=", n1);Block Level Scope
Block Scope 的 Java 例子
JavaScript 的 var 在 Block Scope 使用的例子
對,傳統 JavaScript 只有 Global 和 Function 兩種等級的作用域
References
Last updated
Was this helpful?




