0

Since both falls in the "Timers" phase of Event Loop in Javascript/Node.js -

let racer = function () {
  setInterval(() => { console.log('Interval is here') }, 2000);
  setTimeout(() => { console.log('Timeout is here') }, 2000);
}

Just looking for initial order of execution of above code snippet?

3
  • 1
    All JavaScript platforms I know of honor the order of timer registration, so your interval timer would fire before the timeout. Commented Aug 22, 2019 at 14:43
  • 1
    First the setInterval will be executed and then the setTimeout. As for which callback will fire first, it's almost guaranteed to be the interval, then the timeout. Commented Aug 22, 2019 at 14:44
  • So just order matters in this case? Commented Aug 22, 2019 at 14:46

1 Answer 1

1

W3C specification does not seem to indicate any priority between the list of active timeouts and the list of active intervals.

Therefore the execution order of your racer function depends on browser implementation.

Sign up to request clarification or add additional context in comments.

1 Comment

That's what my question was. I haven't found any concept like that. To few people it may seems like silly question but there is no actual proof or explanation given. Thanks for the clarification.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.