发现自己的概念混乱不清楚,下面的输出结果就是证据:
function sayHi() {
console.log(name);
console.log(age);
var name = '111';
let age =222;
}
sayHi();
输出结果是:
undefined 和 ReferenceError;
var: 变量提升并且初始化;
let: 变量提升但不会初始化
类似于下面的代码:
function sayHi() {
var name;
console.log(name);
console.log(age);
name = '111';
let age =222;
}
sayHi();