function fn(a, c) {
// console.log(ggggg); // Uncaught ReferenceError: ggggg is not defined
console.log("xx : ", xx);
console.log("yy : ", yy);
console.log("zz : ", zz);
var xx = function () {};
function yy() {}
var zz = 666;
console.log("xx : ", xx);
console.log("yy : ", yy);
console.log("zz : ", zz);
console.log("=================");
console.log("a : ", a);
console.log("b : ", b);
console.log("c : ", c);
console.log("d : ", d);
console.log("f : ", f);
console.log("----------------");
a();
// console.log("abc : ", abc); // Uncaught ReferenceError: abc is not defined
var a = 123;
console.log("a : ", a);
function a() {
console.log("function a() ...");
console.log("abc - a() : ", abc);
// 第一次編譯期 變量不會提升 調(diào)用函數(shù)a() 創(chuàng)建a()的AO{}后提升
var abc = 999;
}
console.log("a : ", a);
// a(); Uncaught TypeError: a is not a function
if (false) {
var d = 678; // 編譯期 變量也會提升
}
for (let index = 0; index < 10; index++) {
var f = index; // 編譯期 變量也會提升
}
var b = function () {};
function c() {}
console.log("----------------");
console.log("a : ", a);
console.log("b : ", b);
console.log("c : ", c);
console.log("d : ", d);
}
fn(1, 2);
xx : undefined
yy : ? yy() {}
zz : undefined
xx : ? () {}
yy : ? yy() {}
zz : 666
=================
a : ? a() {
console.log("function a() ...");
console.log("abc - a() : ", abc);
var abc = 999;
}
b : undefined
c : ? c() {}
d : undefined
f : undefined
----------------
function a() ...
abc - a() : undefined
a : 123
a : 123
----------------
a : 123
b : ? () {}
c : ? c() {}
d : undefined
編譯期 1.形參和變量聲明賦值undefined -> 2.形參賦值 -> 3.函數(shù)聲明賦值
AO{
--------------|-----|------------------|
a: undefined | 1 | function a() {} |
c: undefined | 2 | function c() {} |
b: undefined | | |
d: undefined | | |
}