First of all, I know that JavaScript is single-threaded. Suppose I have a counter that displays its values every second.
var counter = 0;
setInterval(function(){
console.log("Interval: " + ++counter);
}, 1000);
At some point, I want to call code that stops the execution of a script. For example, a warning message.
setTimeout(function(){
alert("Some alert message");
},10000);
At this point, when a warning message appears, the interval code will be stopped. Is there a trick to keep it from running?
source
share