变量提升(预解析)
优点
1.提高性能,提前为变量分配空间
2.提升容错率
缺点
1.不规范的定义会使得某些变量的undefined
2.结构混乱,维护麻烦
a存在变量提升,所以a等于undefined
var a = 1;
let b = 4;
(function() {
console.log(a);//undefined
var a = 3;
let b = 4;
console.log(a, b);//3,4
})()
var a = 1;
let b = 4;
function try1() {
var a = 3;
console.log(a);//undefined
let b = 4;
console.log(a, b);//3,4
};
try1()
作用域内未定义a
var a = 1;
let b = 4;
(function() {
console.log(a); //1
let b = 4;
console.log(a, b); //3,4
})()
var a = 1;
let b = 4;
function try1() {
console.log(