Test your reflexes and measure your reaction speed in milliseconds.
To measure your reaction time, the code simply records the time when the screen turns green, records the time when you click, and subtracts the two numbers. However, the way you record that time matters significantly.
Many beginner JavaScript programs use Date.now(). This relies on the system clock. The problem is that the system clock can be adjusted mid-game (e.g., by an NTP server synchronizing your computer's time with the atomic clock).
If the clock jumps forward 50ms while you are reacting, your score is ruined. Alternatively, a user could manipulate their system clock to fake a perfect score.
For precision measurements, browsers provide the performance.now() API. This represents a high-resolution, monotonically increasing timer.
150.45ms).This tool uses performance.now() to ensure that your reaction time is measured with hardware-level accuracy, unaffected by operating system clock drift.
Why should you avoid using Date.now() to measure short durations like reaction times?