为什么以下行没有发出警报?
<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 - javascript警报方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14628273/