js-严格模式.html

<script type="text/javascript">
//本身 js 的开发过程不是很严谨

//严格模式是指开发过程所写的代码有一些要求
//如果不满要求,直接报错

//开户严格模式
//在作用域的一开始写字符串'use strict'

'use strict'

//1.变量必须写var
var num =100
console.log(num) //100
document.writeln(num) //100

//2.函数的形参不能重名
//形参是在函数体内使用的变量
function fn(a,b){
console.log(a,b) //20 10
}
fn(20,10)

//3.全局函数没有this
function fun(){
console.log(this) //undefined
}
fun()
</script>

猜你喜欢

转载自www.cnblogs.com/d534/p/12893200.html