変数の巻き上げ
スコープ内でvarにより定義された変数は、スコープの先頭で定義されたように動作する varの場合は、undefined
code:js
var x = 0;
(function () {
console.log(x); // undefined
var x = 1;
console.log(x); // 1
})();
code:js
var x = 0;
(function () {
console.log(x); // Uncaught ReferenceError: Cannot access 'x' before initialization
let x = 1;
console.log(x);
})();