title: Does Javascript event queue have priority?
body: <p>These days, I have read some documents about <code>setTimeout</code> and <code>setInterval</code>. I have learned that the Javascript is a single thread which will only execute one piece of code per time. At the same time, if there is a event happens, it will be pushed into the event queue and block until appropriate time. I want to know, when many events are blocked waiting to execute at the same time. Do these events have different priorities, so the high priority event will execute before the low ones. Or just a FIFO queue.</p>
  <pre><code>setTimeout(fn1, 10);
  $(document).click(fn2); //will be called at 6ms;
  $.ajax({ajaxSuccess(fn3); //async request,it uses 7ms;})
  
   for () {
      //will run 18ms;
  };
  </code></pre>
  <p>In the above code, the setTimeout fn1 will happen at 10 ms,click event handler fn2 will at 6ms, ajax callback fn3 will at 7ms, but all the three functions will be blocked until the for loop finish. At 18ms, the for loop finished, so what order does these functions will be invoked.(fn1,fn2,fn3) or (fn2,fn3,fn1)</p>