The value returned with setTimeout is a unique identifier that you can use later to cancel the timeout with clearTimeout .
var timeout; function timer () { timeout = setTimeout(); } function resetTime() { stopTime(); timer(); } function stopTime() { clearTimeout(timeout); }
source share