Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why would I use the clearTimeout method?

I have any ideas where we can need it?

1 Answer

Straight from the MDN website.

A simple example would be for an alarm. I want to set an alarm for 1pm, it's currently 10pm. So let's say we had an alarm.

When I set an alarm, I want it to show an alert that says a message like 'Wake Up'. So I set it for 1pm. - Let's say the remind method just uses setTimeout(callback, timeTo10Pm) An hour later (11pm) I decided to cancel that alarm - The cancel method would need to use clearTimeout to stop it