title: How can I synchronize accessing a global var across two external JS files
body: <p>test.html</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script src = "./test1.js"&gt;&lt;/script&gt;
          &lt;script src = "./test2.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>test1.js</p>
  
  <pre><code>var a;
  $(document).ready(function(){
      setTimeout(function(){
          a=10;   
      },1000);
  });
  </code></pre>
  
  <p>test2.js</p>
  
  <pre><code>$(document).ready(function(){
      //Busy waiting... doesn't Work.
      /*while(typeof(a) === "undefined"){
          console.log(a);
      };*/
      console.log(a);
  });
  </code></pre>
  
  <p>test2 prints 'a' is 'undefined'...
  How can I synchronize 'a' over two javascript files?</p>