FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Cancellable Timeout

10mins

Implement a function cancellableTimeout(callback, delay) that behaves like setTimeout but returns a function to cancel the pending callback.

Example

let called = false; const cancel = cancellableTimeout(() => { called = true; }, 100); cancel(); // Cancel the timeout before it runs console.log(called); // false

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests