Home
← All questions

Polyfill for clearAllTimeout in JavaScript

MediumPremiumJavaScript

Asked at Dream11

JavaScript interview practice: Track every setTimeout id and clear them all at once via clearAllTimeout().

Problem

Implement clearAllTimeout() that cancels every pending timeout created with setTimeout. Use an IIFE to wrap the native setTimeout and keep a registry of timer ids.

// after setting several timeouts, clearAllTimeout() should cancel them all
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium