var test = 10;
function test() {
}
test();// Uncaught TypeError: test is not a function(…)
按照我的理解,后面的函数不是应该覆盖前面的变量test吗?为什么会报错吗?
var和function申明会提升,test=10赋值是实际运行后才赋值的,所以test为10,等价于下面的
var test=undefined
function test(){}
test=10
test()
var test = 10;
test = function() {
}
test();