严格模式

ES6模块自动采用严格模式(‘use strict’), 严格模式下:

  1. 变量必须声明 Object/Value
    1
    a = 20;  // > a=20
1
2
'use strict';
a = 20; // > a is not defined
  1. 不能delete 变量/Function

    1
    2
    3
    'use strict';
    var a = 20;
    delete a; // false
  2. 函数参数名不能重复

    1
    2
    3
    4
    5
    'use strict';
    function testParamsName(p1, p1) {
    console.log(p1);
    }
    // 报错: Duplicate parameter name not allowed in this context
  3. 不能使用八进制字符

1
2
"use strict";
var a = "\010"; // 报错: Octal escape sequences are not allowed in strict mode.