您的位置:首页 > Web前端 > JavaScript

javascript variable's scope , 变量 范围

2009-07-26 23:57 309 查看
Detailed example that writes to this page:

You can reference all local variables inside the same function the variables are declared.

(L1) local variable declared with var keyword

(L2) local variable declared without var keyword

(L3) local variable declared with var keyword inside if statement

You can reference all global variables inside any function.

(G1) global variable declared with var keyword

(G2) global variable without var keyword

(G3) global variable declared with var keyword inside if statement

Outside a function, you can only reference local variables that are not declared with the var keyword.

Commented out. Cannot reference (L1)

(L2) local variable declared without var keyword

Commented out. Cannot reference (L3)

Outside a function, you can reference all global variables.

(G1) global variable declared with var keyword

(G2) global variable without var keyword

(G3) global variable declared with var keyword inside if statement
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐