O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

How setTimeout works

Let’s step through what just happened.

  1. When the page loads we do two things: we define a handler named timerHandler, and we call setTimeout to create a time event that will be generated in 5000 milliseconds. When the time event happens, the handler will be executed.

  2. The browser continues its normal job as the timer counts down in milliseconds.


    Cover of Head First JavaScript Programming


    what is the difference between setTimeout, setInterval, and cleanInterval functions?