10

I am trying to find out exactly how JavaScript timers work. In particular whether a timer function is executed immediately the timer expires or instead when the JavaScript engine is in some kind of idle state.

For example if the JavaScript engine is executing a block of code and a timer goes off does the execution of the block of code get interrupted and the timer function called. Or does the JavaScript engine wait until it returns to some kind of idle state before it calls the timer function?

Thanks,

AJ

1
  • Great question, I'm wondering the same thing.. For example if some JS code is checking the size of an element in the DOM, but the timer goes off when the browser hasn't completed the rendering yet. Commented Feb 5, 2010 at 17:50

1 Answer 1

12

Here's a very good explanation from John Resig

how-javascript-timers-work

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

Comments

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.