无论我是在变量之前还是之后定义函数
或者,如果我在变量之前定义函数。
var a = 1;
function a() {};
typeof a // number
或者,如果我在变量之前定义函数。
function a() {};
var a = 1;
typeof a // number
最终的typeof
结果始终为number
我在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.
但是这似乎没有效果。
那么我该如何解释呢?
var a = function(){};
并查看typeof
返回的结果。 - asawyer