title: Why a variable defining with window object giving undefined value?
body: <p>I have read that when we declare a variable with <strong>window</strong> object inside a function then it becomes a <strong>global</strong> variable i.e. we can access that variable outside the function.</p>
  
  <p>but I am getting the problem when accessing that global variable and it is giving <strong>undefined</strong> as output.</p>
  
  <p>Below is the code snippet: </p>
  
  <p><strong><em>window.js</em></strong></p>
  
  <pre><code>function m(){  
      window.value=100;//declaring global variable by window object  
  }  
  
  function n(){  
      document.write("Global var value: "+ window.value);//accessing global variable from other function  
  }
  </code></pre>
  
  <p><strong><em>window.html</em></strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript" src="window.js"&gt; &lt;/script&gt; 
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt; This is global variable test. &lt;/p&gt;
          &lt;form&gt;
              &lt;input type="button" onclick="n()" value="Click!!"/&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h2><strong><em>output</em></strong></h2>
  
  <p><strong>Global var value: undefined</strong></p>
  
  <p>Please help me on this.</p>