我创建了一个包含两个脚本的 HTML 文件
看起来像这样
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src='src/moduleOne.js'></script>
<script src='src/moduleTwo.js'></script>
</body>
</html>
而且javascript的第一个模块代码简单
(function() {
let hello = 'frank';
})();
第二个里面有函数
(function() {
function problemIsNotOccur() {
return name === undefined;
}
console.log(problemIsNotOccur());
})();
应该发生的是名称应该返回 Error name is undefind or return undefined value
但是
name return '' empty string(我不明白为什么会这样)
最佳答案
你的问题在你的case name is not defined because is not declared中不清楚
(function() {
let name; ///name now is undefined
function problemIsNotOccur() {
return name === undefined; /// return true
}
console.log(problemIsNotOccur());
})();
关于javascript - 我在为家庭作业构建模块时获得了意想不到的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58502170/