JavaScript strict mode

  1. Do not enable strict mode The
    following html pages can be executed normally when opened in a browser
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script type="text/javascript">
		i=10
		alert(i)
	</script>
</head>
<body>

</body>
</html>
  1. Enable strict mode
    Add the string "use strict" to the first line of the script, then let or var must be added when the variable i is declared . Therefore, when the following code is opened in the browser, an error will be reported
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script type="text/javascript">
		"use strict"
		i=10
		alert(i)
	</script>
</head>
<body>

</body>
</html>

Guess you like

Origin blog.csdn.net/weixin_40315481/article/details/104773940