title: Can Javascript Ajax lead to deadlocks?
body: <p>I have a thought experiment. In my code I have a global variable say <code>var changeMe;</code> and I'm making few Ajax calls.</p>
  
  <pre><code> //call One -- third param is the callback function
      ajaxFunction(url1, params,function(data){
          changeMe = data;
      });
  
  //call Two
      ajaxFunction(url2, params,function(data){
          changeMe = data;
      });
  </code></pre>
  
  <p>So <code>changeMe</code> value will depend on which Ajax call <strong>finishes last</strong>, which means the call that finishes last will overwrite the value.</p>
  
  <p>What if both calls finish exactly at <strong>the same time, same timestamp</strong>?</p>
  
  <p>Since Javascript is single-threaded we normally won't get this problem, but this may arise in the case of <code>setTimeout</code> and Ajax calls. I don't know how I can replicate this issue with precision, so it still remains a thought experiment.</p>
  
  <p>So how in multi-threaded conditions is a deadlock handled?</p>
  
  <p>I prefer an answer like <code>changeMe</code> will be <code>url1</code> or <code>url2</code> , and a clear situation explanation..</p>
  
  <p>Thanks in advance</p>