9.1 概览
ES6 新增了两个定义变量的关键字:let 与 const,它们几乎取代了 ES5 定义变量的方式:var。
9.1.1 let
let 语法上非常类似于 var,但定义的变量是语句块级作用域,只存在于当前的语句块中。var 拥有函数作用域。
在如下的代码中,let 定义的变量 tmp 只存在于行 A 开始的语句块中:
function order(x, y) {
    if (x > y) { // (A)
        let tmp = x;
        x = y;
        y = tmp;
    }
    console.log(tmp === x); // ReferenceError: tmp is not defined
    return [x, y];
}
9.1.2 const
const 和 let 类似,但是定义变量时必须初始化值,并且是只读的。
const foo;
    // SyntaxError: missing = in const declaration
const bar = 123;
bar = 456;
    // TypeError: `bar` is read-only
9.1.3 定义变量的方式
下面的表格对比了在 ES6 中定义变量的 6 种方式:
| Hoisting | Scope | Creates global properties | |
|---|---|---|---|
| var | Declaration | Function | Yes | 
| let | Temporal dead zone | Block | No | 
| const | Temporal dead zone | Block | No | 
| function | Complete | Block | Yes | 
| class | No | Block | No | 
| import | Complete | Module-global | No |