先看一段代码:
function test(a,b)
{
console.log(a);
console.log(b);
var b = 234;
console.log(b);
a = 123;
console.log(a);
function a() {}
var a;
b = 234;
var b = function () {}
console.log(a);
console.log(b);
}
运行结果为:
js的函数预编译步骤:
1.创建AO对象
2.函数中声明的变量和实参放入AO对象中,值为undefined
3.实参与形参统一
4.在函数体中找函数声明将函数声明放入AO对象中,值为函数体
注意:函数声明与函数表达式是不同的 函数声明:function a() {} 函数表达式:var a = function () {}