1:严格模式’use strict’
一:优点
1:减少代码中不合理的地方,保证js代码的运行安全
2提高编译效率
3为未来js版本做铺垫
二:严格模式下
1:不能使用未声明的变量
<script>
name=20;
console.log(name) //20
</script>
<script>
'us strict' //严格模式下;
age=18;
console.log(age)
</script>
2:在严格模式下,函数如果没有调用者,this指向null或undefined
<script>
function fn(){console.log(this)}
fn() //输出window对象
</script>
<script>
'use stricr'
function fn(){console.log(this)}};
fn() // 输出undefined
</script>
3:在严格模式下,arguments元素改变,对应的形参不会改变;
<script>
function fn(a,b){
arguments[0]=20;
console.log(a+b);
}
fn(10,20) //输出四十,对应的形参被改变
</script>
<script>
'use strict' //严格模式
function fn(a,b){
arguments[0]=20;
console.log(a+b)
}
fn(10,20) //输出30;严格模式不能通过arguments改变对应的形参值
</script>
4:在严格模式下,delete不能删除变量
<script>
'use strict' //严格模式
var name=20;
delete name;
console.log(name);
</script>
<script>
//'use strict' 非严格模式下
var name=20;
delete name;
console.log(name);
</script>
5:在严格模式下,arguments不可以重新赋值,
6:在严格模式下不可以使用八进制
7;在严格模式下,不可以使用with语句
8:不能使用fn.caller和fn.arguments获取函数调用的堆栈
9:新增了保留字:
implements,interface,let,package,private,protect,public,static,yield。