gpt4 book ai didi

JavaScript 警报方法

转载 作者:行者123 更新时间:2023-11-28 16:06:43 26 4
gpt4 key购买 nike

为什么以下行没有警报?

  <script>
alert(x);//this line is not executed or alerted ???.It should have alerted "undefined"
console.log(x)//reference error
var y="maizere";
alert(y);//this line is also not executed or alerted ???

</script>

任何未声明的变量在 JavaScript 中都会被视为全局变量,对吧?

最佳答案

alert(x);//this line is not executed or alerted  ???.It should have alerted "undefined" 

这是不正确的。此行引发 ReferenceError,因为没有变量 x

将此与情况进行对比:

var obj = {};
alert(obj.x); // undefined - there's no attribute x

关于JavaScript 警报方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14628273/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com