1. let声明变量有严格的作用域
在大括号内, b在外边是访问不到的, 有严格的作用域
<script> { var a = 1; let b = 2; } console.log(a) console.log(b) </script>
2.let只可声明一次变量, var可多次声明
<script> var a = 1; let b = 2; console.log(a); console.log(b); var a = 11; let b = 22; console.log(a); console.log(b); </script>
3.var可以变量提升, let不可以
var可以自己转换为undefined, let就是报错
<script> console.log(a); var a = 1; console.log(b); let b = 2; </script>