title: Declaring Variables Outside of Functions
body: <p>What kind of variables can be declared outside of functions in JavaScript? I'm having a bit of trouble understanding the following code.</p>
  
  <p>This code doesn't affect <code>subtitle</code>.</p>
  
  <pre><code>var element = window.document.getElementById("subtitle");
  var test = "Changed!";
  
  function check(){
      element.innerHTML = test;
  }
  </code></pre>
  
  <p>However, if I move <code>element</code> inside the function, then the <code>subtitle</code> element changes to "Changed!".</p>
  
  <pre><code>var test = "Changed!";
  
  function check()
  {
      var element = window.document.getElementById("subtitle");
      element.innerHTML = test;
  }
  </code></pre>
  
  <p>Is there a rule that says <code>window</code> objects can't be  assigned to <code>var</code> outside of a function, is there a mistaken in the code, or am I just not understanding JavaScript variables?</p>