5

Possible Duplicate:
Why does IE nuke window.ABC variables?

<!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>

In IE8, the result is

1=[object Object]
2=undefined
3=undefined
4=undefined

The second script seems to override the q of window.

If I change the code to window.q = {test: "test"}; of the first script to q={test:"test"}, the result will be the same as other browsers.

Is this a bug in IE?

Community
  • 1
  • 1
user1039304
  • 365
  • 5
  • 10

1 Answers1

2

Looks like a bug to me. In IE 10, the above yields

1=[object Object]
2=[object Object]
3=test
4=test

This is the same behaviour as Firefox.

EDIT: See also https://stackoverflow.com/a/2635726/1641070 and Why does IE nuke window.ABC variables?

Community
  • 1
  • 1
Lukas_Skywalker
  • 2,053
  • 1
  • 16
  • 28