1// setTimeout:
2// Calls a function or evaluates an expression after a specified number of milliseconds.
3// Doesn't mean that the function will be called after the exactly specified interval.
4// Can cause a browser to miss the frame.
5// requestAnimationFrame
6// Works similarly to setTimeout
7// called right before the next repaint in the browser occurs.
8
9const timestamp = setTimeout(() => {...}); // runs as frequently as possible
10const requestId = requestAnimationFrame(() => {...}); // runs once per frame
11
12clearTimeout(timestamp); // clear previously added timeout
13cancelAnimationFrame(requestId); // cancel an animation frame request