let 声明及其特性
1、声明变量
let b, c;
let d = "chen"; // 变量赋值
let e = 123, f = 'zc', g = [] // 可以批量赋值
2、特性
2.1 变量不能重复声明
let h = 'stu';
let h = 'tea';
console.log(h) // 报错
2.2 块级作用域,let 声明的变量只在块级作用域内有效
function fun() {
let i = 2;
console.log(i)
}
console.log(i) // 报错
fun()
2.3 不存在变量提升,或者说它提升了,但是ES6规定了在let声明变量前不能使用该变量,可以称这特性为“在暂时性死区”
function fun() {
console.log(j) // 报错
let j = 'web';
}
fun()