- 不开启strict模式
以下html页面在浏览器中打开时可以正常执行
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
i=10
alert(i)
</script>
</head>
<body>
</body>
</html>
- 开启strict模式
在script的第一行加上字符串“use strict”,则变量i声明时必须加上let或者var,因此以下的代码在浏览器中打开时,将会报错
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
"use strict"
i=10
alert(i)
</script>
</head>
<body>
</body>
</html>