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
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
相关文章推荐
- 关于在VS2008中的Stack around the variable '' was corrupted.即(堆栈被破坏周围的变量)解决办法
- 全局变量报错:UnboundLocalError: local variable 'l' referenced before assignment
- 全局变量报错:UnboundLocalError: local variable 'l' referenced before assignment
- JavaScript 给变量初始化null ,隐式转换为 'null'
- 使用JDK提供的ThreadLocal实现线程范围的共享变量(类似于Map<Thread,Variable>)
- 全局变量报错:UnboundLocalError: local variable 'l' referenced before assignment
- Javascript 中变量的作用范围引发的bug
- JavaScript:Scope &Closure 变量作用域和闭包
- SQLSERVER出错提示:此上下文中不允许使用''。此处只允许使用常量、表达式或变量。不允许使用列名。
- Visual Studio2015错误C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_
- 对Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.的处理以及理解
- Run-Time Check Failure #2 - Stack around the variable 'usval' was corrupted
- Python的UnboundLocalError: local variable 'xxx' referenced before assignment
- ns2中can't read "debug_": no such variable类似问题
- Variable's Day Out #6: Innodb_buffer_pool_reads
- JavaScript_A Beginner's Guide - Introduction to JavaScript - 09/19/2012
- 错误 1 error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead.
- Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
- 关于 local variable 'has' referenced before assignment 问题
- 源码-JavaScript&jQuery交互式前端开发-第2章-JavaScript基础指令-使用变量来存储字符串