一、变量
1、不允许意外创建全局变量
"use strict";
string= 'hello world!';
2、不能对变量调用delete操作符
"use strict";
var color = 'red';
delete color;
二、对象
1、不能是只读属性赋值
"use strict";
var obj= {
name:'leying'
};
Object.defineProperty(obj,'name',{
writable: false
});
person.name = 'lileying';
2、不能为不可配置的属性使用delete操作
"use strict";
var obj= {
name:'leying'
};
Object.defineProperty(obj,'name',{
configurable: false
});
delete obj.name;
三 、函数
1、参数必须唯一
"use strict";
function sun(num,num){
//TODO
}
2、修改形参不会反映到arguments中
function showValue(value){
value = "hello";
alert(arguments[0]);
//非严格模式:"hello"
//严格模式:"Hi"
}
showValue("Hi");
3、不允许使用arguments.callee和arguments.caller
"use strict";
function fn(num){
return arguments.callee(num);
}
fn(2);
"use strict";
function outer(){
inner();
}
function inner(){
alert(inner.caller());
}
outer();
4、不允许eval()在包含上下文中创建变量或函数
"use strict";
function fn(){
eval("var x=10");
alert(x);
}
fn();
5、不允许使用eval和arguments作为标识符,也不允许读写他们的值
"use strict";
var eval = 10;
var arguments = 20;
6、不允许this值为null或undefined
"use strict";
var color = "blue";
function fn(){
alert(this.color);
}
fn();
7、不允许使用with语句
"use strict";
with(location){
alert(href);
}
8、不允许使用八进制字面量
"use strict";
var value = 010;