Wie stoppt man den Timer mit einer anderen Funktion javascript

So habe ich diesen Code

function timer()
{
     setTimeout(function(){alert("Out of time")}, 3000); //Alerts "Out of time" after 3000 milliseconds
}
function resetTime()
{
     timer(); //this is not right, i thought it would override the first function but it just adds another timer as well which is not what I want
}
function stopTime()
{
     //What could go here to stop the first function from fully executing before it hits 3000 milliseconds and displays the alert message?
}

Die Funktion timer () startet, wenn die Seite geladen wird. Wenn ich jedoch eine Schaltfläche für stopTime () habe und darauf klicke, wie kann ich die Ausführung der ersten Funktion stoppen und verhindern, dass sie die 3000-Millisekunden-Marke erreicht und die Meldung "Out of" ausgibt Zeit"

Antworten auf die Frage(6)

Ihre Antwort auf die Frage