संभव डुप्लिकेट:
Why does IE nuke window.ABC variables?IE में वैश्विक चर विषमताएं
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<script>
if(typeof q === "undefined"){
window.q = {test: "test"};
}
alert("1="+q)
</script>
<script>
alert("2="+q)
if(typeof q === "undefined"){
var q = {};
}
alert("3="+q.test)
</script>
<script>
alert("4="+q.test)
</script>
</body>
IE8 में, परिणाम
1=[object Object]
2=undefined
3=undefined
4=undefined
है
दूसरा script
window
के q
को ओवरराइड करना प्रतीत होता है।
यदि मैं पहले script
से q={test:"test"}
में window.q = {test: "test"};
पर कोड बदलता हूं, तो परिणाम अन्य ब्राउज़रों के समान होगा।
क्या यह आईई में एक बग है?
यह केवल IE 8. IE 9+ काम ठीक में हो रहा है। –