Hoisting 是 JavaScript 在编译阶段将 declarations 移到其作用域顶部的行为,这发生在任何代码运行之前。但是如何 hoisted 某个东西取决于声明类型。
js
console.log(a); // undefined — `var a` is hoisted & initialized to undefined
var a = 1;
foo(); // "works!" — function declarations are fully hoisted
function foo() { console.log("works!"); }
console.log(b); // ❌ ReferenceError — temporal dead zone
b = ;
什么被 hoisted,以及如何 hoisted
为什么这很重要
Hoisting 解释了
