Implement a cancellable timer function
Timers are probably the most used BOM API’s, using which we can schedule callbacks to be executed after a wait time.
We need to implement a higher order utility function for both setTimeout
and setInterval
API’s which returns a cancel
function cancelling the timer.
1. Cancel setInterval implementation
2. Cancel setTimeout implementation
This is exactly same as setInterval, with only difference that we replace setInterval with setTimout.
Further Reading
I strongly encourage you to explore and tackle additional questions in my Closure Questions for Frontend Interviews blog series.
By doing so, you can enhance your understanding and proficiency with closures, preparing you to excel in your upcoming frontend interviews.
Wishing you best. Happy Interviewing 🫡.