Dev UtilitiesLesson 144Free preview
Online Stopwatch
This lesson is part of Web Developer Tools · All levels
Summary
Online stopwatches measure intervals with start, stop, and reset buttons, and often provide lap time. In JavaScript, the runtime is calculated from the time stamp difference starting with the current time, then accumulated each time it is paused. For measurements that are unaffected by system clock changes, use performance.now().
Key points
- Elapsed time is calculated from the current time minus the start time
- It gives you monotonous time with high resolution
- When stopping, keep the total elapsed to the accumulated variable
- SetInterval only updates the display, not the source of the truth of time
- Lap time records the time difference between rounds
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.