JS TutorialLesson 17Free preview
JS Timers
This lesson is part of JavaScript · All levels
Summary
JavaScript provides a timer to run code after a certain pause with setTimeout or repeatedly with setInterval. Both work asynchronously based on milliseconds, so that other code stays running while waiting for its time to arrive. Timers can be canceled with clearTimeout and clearInterval using the id returned when the timer was created.
Key points
- Run the function once after a millisecond break
- Running a repeating function every millisecond break
- Both functions return the id that can be used to cancel the timer.
- Asynchronous timers: statements after the setTimeout remained executed first
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.