严格模式 严格模式下不允许使用0前缀: var color = 0100;禁止八进制的前缀0表示法。函数不能有重名的参数。eval、arguments 不可用作标识名。禁止扩展的对象不可扩展。只设置了取值器的属性不可写。只读属性不可写。严格模式下,变量都必须先声明,然后再使用。禁止 this 关键字指向全局对象。禁止使用 fn.callee、fn.caller。禁止使用 arguments.callee、arguments.caller。禁止删除变量。禁止使用 with 语句。arguments 不再追踪参数的变化。创设 eval 作用域。非函数代码块不得声明函数: 注意,如果是 ES6 环境,允许在代码块之中声明函数。保留字:为了向将来 JavaScript 的新版本过渡,严格模式新增了一些保留字(implements、interface、let、package、private、protected、public、static、yield等)。使用这些词作为变量名将会报错。 不使用严格模式 functionA() { console.log(this); //undefined } A.call(); //window A.call(1); //Number{1} A.call(true); //Boolean{true} A.call(undefined); //window A.call(null); //window 使用严格模式 function A() { "use strict" console.log(this); } A.call(); //undefine A.call(1); //1 A.call(true); //true A.call(undefined); //undefine A.call(null); //null