一:let用法三个特性
1)声明变量,没有变量提升(没有声明之前不能使用)
2)是一个块作用域
3)不能重复声明
<script> //1. let申明变量,没有变量提升 //Uncaught ReferenceError: a is not defined console.log(a) //let a=10; //2. 是一个块作用域 if (1===1){ let b=10; } //1.html:15 Uncaught ReferenceError: b is not defined //console.log(b) //3.不能重复声明 let a=10; let a=20; //Uncaught SyntaxError: Identifier ‘a‘ has already been declared console.log(a) </script>
二:const用法
1)声明常量,一但被声明,不能修改
2)声明,没有变量提升(没有声明之前不能使用)
3)是一个块作用域
4)不能重复声明
原文:https://www.cnblogs.com/lixiang1013/p/13584605.html