Categories
JavaScript Answers

How to reset setTimeout with JavaScript?

Spread the love

Sometimes, we want to reset setTimeout with JavaScript.

In this article, we’ll look at how to reset setTimeout with JavaScript.

How to reset setTimeout with JavaScript?

To reset setTimeout with JavaScript, we can call the clearTimeout function.

For instance, we write

const myTimer = setTimeout(() => {
  //...
}, 115000);

//...

clearTimeout(myTimer);

to call setTimeout to return a timer ID number and run the function after 115000 milliseconds.

Then we call clearTimeout with myTimer to stop the timer.

Conclusion

To reset setTimeout with JavaScript, we can call the clearTimeout function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *