// 开启严格模式:更加规范的书写js代码
// 1.全局的严格模式
// "use strict";
// 2.立即执行函数中开启严格模式
(function () {
"use strict"
})();
// 3.函数中开启严格模式
function fn() {
"use strict"
}
- 函数的参数不能重名
function add(a, a) {
console.log(a + a)
}
add(2, 4)
// - 构造函数需要使用new,不能直接调用
function Person(gender) {
this.gender = gender
}
Person('男')
- 全局的函数中的this是undefined
function fn() {
console.log(this) //undefined
}
fn()
- 不能删除已经声明的变量 - 例如: delete a
var num = 'hello'
delete num
console.log(num)
- 声明变量必须加关键字var
a = 10
console.log(a)
|