严格模式   只需要在代码首部加入字符串“use strict”, 必须在首部,首部是指其前面没有任何有效的js代码注释,否则无效。

eg:

"use strict";

function(){

console.log(a) ;

}

注意事项:

1.不适用var声明变量,严格模式中奖通不过;在循环中如果没有声明变量,在非严格模式中,i会不小心溢出成为全局变量,在严格模式中会报错。

2.不推荐在整个脚本中使用严格模式

3.严格模式中不允许使用with

4.严格模式下,arguments变为参数的静态副本。非严格模式下,arguments对象里的元素和对应的参数是指向同一个值的引用

!function(a) {
arguments[0] = 100;
console.log(a); //100
}(1);

!function(a) {
'use strict';
arguments[0] = 100;
console.log(a); //1
}(1);

但是:传的参数是对象除外。arguments和形参共享传递。

!function(a) {
'use strict';
console.log(a.x); //1
arguments[0].x = 100;
console.log(a.x); //100
}({x: 1});
5.严格模式不允许八进制整数直接量

....