hh5*_*188 7 javascript variables declaration function
无论我是否在变量后定义函数
var a = 1;
function a() {};
typeof a // number
Run Code Online (Sandbox Code Playgroud)
或者如果我在变量之前定义函数
function a() {};
var a = 1;
typeof a // number
Run Code Online (Sandbox Code Playgroud)
最后的typeof结果总是如此number
我execution context在http://davidshariff.com/blog/what-is-the-execution-context-in-javascript/找到了一些解释
Before executing the function code, create the execution context.
......
Scan the context for variable declarations:
If the variable name already exists in the variable object, do nothing and continue scanning.
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.
那我怎么解释呢?
这与JavaScript的变量提升有关.试试这个:
var a = 1;
var a = function() {};
typeof a // function
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
604 次 |
| 最近记录: |