1.不存在变量提升
<script>
console.log(b); //undefind
var b = 1;
console.log(a);//直接报错不能进行下一步 Uncaught ReferenceError: Cannot access 'a' before initialization
let a = 1;
</script>
<script>
console.log(b); //undefind
var b = 1;
console.log(c);
const c=10;//直接报错不能进行下一步 Uncaught ReferenceError: Cannot access 'a' before initialization
</script>
2.暂时性死区 let在声明之前是不能用的
<script>
var tem=899;
if(true){
tem=1000;
let tem=10;// Uncaught ReferenceError: Cannot access 'tem' before initialization at
}
</script>
3.typeof 不再是完成正确 不再是百分之百的报错
<script>
console.log(typeof c);
</script>
4.不允许重复声明
<script>
//不允许重复声明
let a1=1;
let a1=2;//Identifier 'a1' has already been declared
let x=x;// Cannot access 'x' before initialization
</script>
5.块级作用域
5.1.1 为什么会有块级作用域
<script>
var f1=10;
function fn(){
console.log(a);
if(false){
var a="局部"
}
}
var f2="全局";
(function(){
var f2="局部"
console.log(f2)
}())
console.log(f2);
</script>
网友评论