[英]Why a variable when not declared in a function inside script tag doesn't give error “variable not defined”
例如:
<!DOCTYPE html>
<html>
<head>
<title>TEST PAGE</title>
<script type="text/javascript">
"use strict";
function a () {
i = 0;
}
</script>
<body>
<div> TEST </div>
</body>
</html>
为什么在启用了strict mode
浏览器中执行此HTML页面时,未生成“未定义变量”错误?
因为你永远不执行a
功能。
“使用严格”定义JavaScript代码应在“严格模式”下执行 。严格模式在编译时不起作用。 这就是为什么仅在执行函数但未执行时才会显示错误的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.