javascript - javascript中的name关键字是什么意思?

标签 javascript

我是 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/

相关文章:

javascript - Node js 中的函数外部无法访问外部 IP

javascript - 是否有适用于 sails.js 的良好 MSSQL/SQL Server 适配器?

javascript - 无法将键设置为 for 循环内的对象

javascript - 按 Javascript 数组中的出现次数(计数)排序

javascript - 加载新视频时,videojs 播放列表播放率不会持续存在

javascript - Jquery根据外部div大小更改内部div宽度大小

javascript - WebKit jQuery 动画错误

javascript - 如何在生产环境中禁用 console.log() 并显示横幅?

javascript - CSS 动画在恢复之前下降

javascript - 如何动态地将 html 元素添加到页面并在 asp.net 中访问它们?