1.函數(shù)聲明整體提升
2.變量 聲明提升
3.一切聲明的全局變量十厢,全是window的屬性
預(yù)編譯過(guò)程:
1.創(chuàng)建AO對(duì)象
2.找形參和變量聲明捂齐,將變量和形參作為AO屬性名,值為undefined
3.將實(shí)參值和形參值統(tǒng)一
4.在函數(shù)體里面找函數(shù)聲明奠宜,值賦予函數(shù)體
1
function fn(a){
console.log(a);//function a(){}
var a=123;
console.log(a);//123
function a(){}
console.log(a)//123
var b = function(){}
console.log(b);//function(){}
function d(){}
}
fn(1)
2
function test(a,b){
console.log(a); //1
c=0;
var c;
a=3;
b=2;
console.log(b)//2
function b(){}
function d(){}
console.log(b)//2
}
test(1)
3
function test(a,b){
console.log(a);//? a(){}
console.log(b);//undefined
var b=234;
console.log(b);//234
a=123;
console.log(a);//123
function a(){}
var a;
b=234;
var b=function(){}
console.log(a);//123
console.log(b);//? (){}
}
test(1)
4
console.log(test) //function test(test){
function test(test){
console.log(test) //function test(){}
var test = 234;
console.log(test)//234
function test(){}
}
test(1);
var test = 123
5
var global = 100;
function fn(){
console.log(global) //100
}
fn()
globel = 100;
function fn(){
console.log(globel)//undefiend
globel = 200;
console.log(globel)//200
var globel = 300;
}
fn();
var global;
6
function test(){
console.log(b)//undefiend
if(a){
var b=100;
}
console.log(b)//undefiend
c=234;
console.log(c)//234
}
var a;
test();
a=10;
console.log(c)//234
7
function bar(){
return foo;
foo = 10;
function foo(){}
var foo = 11;
}
console.log(bar()) //function foo(){}
8
var b = "boy";
console.log(b); // boy
function fighting(){
console.log(a); //undefiend
console.log(c); //undefiend
if(a === "apple"){
a = "Alice"
}else{
a = "Ada"
}
console.log(a) //Ada
var a = "Andy";
middle();
function middle(){
console.log(c++); //NaN
var c = 100;
console.log(++c); //101
small();
function small(){
console.log(a) //Andy
}
}
var c = a = 88;
function bottom(){
console.log(this.b); //boy
b = "baby";
console.log(b) //baby
}
bottom();
}
fighting();
console.log(b)//baby