0

As we know, setTimeout handlers will be put into event queue. So my question is that do the setTimeout handlers are executed by order which put it in?

Example:

setTimeout(hander1, 1);
setTimeout(hander2, 1);

Does handler1 will always be executed before hander2 in different browsers?

Ian Jiang
  • 413
  • 7
  • 7
  • 1
    Different browsers might indeed handle very small delays differently. You might find [this article](http://ejohn.org/blog/how-javascript-timers-work/) illuminating. However, if you particularly care about the ordering of asynchronous events, you should do what we _always_ do in that case: put the dependent code in the callback. – Matt Ball Jul 11 '13 at 03:24
  • 1
    You may want to take a look at [this question/answer](http://stackoverflow.com/questions/9647215/what-is-minimum-millisecond-value-of-settimeout). The short of it is that If you need something to depend on something else, don't rely on setTimeout unless it's drastically different. – kalley Jul 11 '13 at 03:25
  • Thanks for pointing out the existing question. – Ian Jiang Jul 11 '13 at 03:31

0 Answers0