Concepts

Cancel pending debounced work

Try the free JavaScript compiler

An optional method defined by the debounce implementation to clear its pending timer. It does not undo work already performed.

Formal Syntax & Structure

javascript syntaxjavascript
debounced.cancel()

Working Example

Example Snippetjavascript
(async () => {function debounce(fn){let id;const run=()=>{clearTimeout(id);id=setTimeout(fn,0);};run.cancel=()=>clearTimeout(id);return run;}let count=0;const run=debounce(()=>count++);run();run.cancel();await new Promise(resolve=>setTimeout(resolve,0));console.log(count);})()
JavaScript Reference