开启严格模式
'use strict' // 全局开启
function fn() {
'use strict' // 局部开启
}
特点
全局变量必须先声明
'use strict'
n = 100 // ❌
禁止用with
const user= {name: 'jack', age: 11}
with(user) {
console.log(name, age)
}
创建eval作用域
'use strict'
var a = 10
eval('var a = 20; console.log(a)') // 20
console.log(a) // 10
禁止this指向window
'use strict'
functoin a() {
console.log(this) // undefind
}
a()
functoin a() {
console.log(this) // window
}
a()