What's the purpose of referencing the window object in Javascript?
<p>Every property of the <code>window</code> object is a global variable. This means you can do something like this:</p>

<pre><code>window.foo = 42;
alert(foo); //alerts 42
var bar = 3;
alert(window["bar"]); //alerts 3
</code></pre>

<p>Because of this, I've always wondered what the purpose was of referencing <code>window</code> in code like this</p>

<pre><code>if(window.prompt("Enter Password") === "secret") {
  window.location.hash = "authorized";
  window.open("secretPage.html");
}
</code></pre>

<p>when you could omit <code>window</code> and have code that does exactly the same thing:</p>

<pre><code>if(prompt("Enter Password") === "secret") {
  location.hash = "authorized";
  open("secretPage.html");
}
</code></pre>

<p>The use also seems inconsistent; I almost never see <code>window.alert</code> but I'll frequently see <code>window.location</code>.</p>

<p>Do people just like referencing <code>window</code> to make their code more verbose? Is there some good reason for doing this that I don't know about?</p>
