Similar to setTimeout(), requestAnimationFrame() returns a request ID which can be used to cancel the request via cancelAnimationFrame().
In the following example, the request callback is enqueued but immediately cancelled:
let requestID = window.requestAnimationFrame(() => { console.log('Repaint!'); }); window.cancelAnimationFrame(requestID);