title: Javascript variables between files
body: <p>Ok, so I have two files , index.html and functions.js (index.html correctly includes functions.js).</p>
  
  <p>When clicking a button in the webpage, a function gets called in the functions file, which updates elements in the web-page (correctly) and attempts to set two global variables ( woind that by doing<code>window.var1</code> and <code>window.var2</code> . No errors so far in the web console.</p>
  
  <p>After this function gets called, in the index.html I run a code of JS that attempts to read <code>window.var1</code> and <code>window.var2</code>, but finds them both to be null.</p>
  
  <p>Why is that ? Could you also please point me to some material regarding as to why this happens, not just the solution ?</p>
  
  <p><em>EDIT</em>
  I am using jquery and jquery mobile. 
  The event handler that calls the two functions is</p>
  
  <pre><code> $('#map').live('pageshow',function(){
              console.debug('clicked button, calling function');
              position(longitude,latitude); //sets the global vars
              initializeMap();
              console.debug('finished with map calling');
          });
  </code></pre>
  
  <p>and sits inside a document.ready() .</p>
  
  <p><em>EDIT 2</em>
  I know am sure that the two functions happen sequentially, I am doing a console.log() at their entry points.</p>