<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>严格模式的变化</title>
</head>
<body>
<script>
'use strict'; // 开启严格模式
// 变量的声明
// num=10;
// console.log(num);
// // 严格模式下的变量声明,必须先声明后使用
// var num2=20;
// console.log(num2);
// 严格模式下不能随意删除声明的变量
// delete num2;
//严格模式下函数的this指向undefined
function add() {
console.log(this);
}
add()
// 定时器的this指向window
setTimeout(function () {
console.log(this);
}, 1000);
// 立即执行函数的this指向window
(function add() {
console.log(this);
})()
// 严格模式函数的参数不能使用重复的参数名
// function add1(a, a) {
// console.log(a);
// }
// add1()
//严格模式下函数不能声明在非函数体中
// if (1) {
// function add11() {
// console.log(this);
// }
// }
// add11()
</script>
</body>
</html>