var a = function(){}和function a(){} 有什么区别
function b(){
document.write("aa");
}
var a=function(){
document.write("123");
}
b();
a();
好像没什么区别
b();
a();
function b(){
document.write("aa");
}
var a=function(){
document.write("123"); // Uncaught TypeError: a is not a function
}
这样再运行一下就有区别了
function b(){} 为函数声明,程序运行前就已存在;
var a = function(){} 为函数表达式,属于按顺序执行,所以a为undefined。
当调用a(),因为a不是function所以抛出Uncaught TypeError: a is not a function错误