我是 javascript 的初学者,我一直在尝试使用变量,直到我遇到这个问题,当我有一个名为 name 的变量时,我评论了它的定义步骤,它仍然具有相同的值,尽管我评论了它. 这只发生在关键字“name”上,那么它是什么?
<script>
// var name="mina"; i commented it now , so if you want to test , enable it once , and then comment it , it will still give you the result although i commented it and deleted the cache
// var name;
alert(name);
</script>
最佳答案
name
不是 Javascript 中的保留字。由于示例代码不在任何特定范围内执行(在函数等内),name
变量引用 window.name
。
console.log(name);
// output: "" (window.name)
(function(){
console.log(name);
})()
// output: undefined
参见 https://developer.mozilla.org/en/docs/Web/API/Window/name了解更多详情。
关于javascript - javascript中的name关键字是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40927541/