clearTimeout()

noun

say it: “kleer TIME-owt” /klɪr ˈtaɪmaʊt/

A JavaScript function that cancels a timer made with setTimeout() before it runs, using the ID that setTimeout() handed back.

What is clearTimeout() in JavaScript?

clearTimeout() — Cancels a timer that setTimeout() set, before it runs. Pass it the ID setTimeout() returned; if the timer has already run, nothing happens.

const reminder = setTimeout(() => console.log('Pizza ready'), 5000);
clearTimeout(reminder); // the order was canceled, so nothing prints

In a sentence

  • “When the shopper clicked Undo, clearTimeout() canceled the order before it was sent.”
  • “I saved the timer's ID in a variable so I could pass it to clearTimeout() later.”

Level: Apprentice · More JavaScript terms at this level

Updated