Is JavaScript multithreaded?
<p>Here's my issue - I need to dynamically download several scripts using jQuery.getScript() and execute certain <a href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> code after all the scripts were loaded, so my plan was to do something like this:</p>

<pre><code>function GetScripts(scripts, callback)
{
  var len = scripts.length
  for (var i in scripts)
  {
    jQuery.getScript(scripts[i], function() 
    {
      len --;
      // executing callback function if this is the last script that loaded
      if (len == 0)
        callback()  
    })
  }
}
</code></pre>

<p>This will only work reliably if we assume that script.onload events for each script fire and execute sequentially and synchronously, so there would never be a situation when two or more of the event handlers would pass check for (len == 0) and execute callback method.</p>

<p>So my question - is that assumption correct and if not, what's the way to achieve what I am trying to do?</p>
