Description

let allows you to declare variables, limiting its scope to the block, statement, or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.

新增的let关键字,让我觉得JS一直在前进,从未停止脚步,而以后支持JS的调试工具会越来越多,编写JS将会和编写其他高级语言一样具有更加严格的规范。

You can use the let keyword to bind variables locally in the scope of loops instead of using a global variable (defined using var) for that.

 
  
  1. for (let i = 0; i<10; i++) { 
  2.   alert(i); // 1, 2, 3, 4 ... 9 
  3.   
  4. alert(i); // i is not defined