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 trialMichael Goodwin
440 PointsIs the cleanup code buggy as written?
The cleanup code as written in the lesson will be executed when the user starts the timer the FIRST time. At this point, the timer id variable is undefined, so the clearInterval
function is called with undefined
as the parameter. JavaScript may handle this gracefully, but it seems like it's a bug. Shouldn't the code only return a cleanup function in the code path where the interval is established (i.e. from inside the if
loop)?