Is setInterval CPU intensive?

I don’t think setInterval is inherently going to cause you significant performance problems. I suspect the reputation may come from an earlier era, when CPUs were less powerful. There are ways that you can improve the performance, however, and it’s probably wise to do them: Pass a function to setInterval, rather than a string. Have … Read more

How to stop “setInterval” [duplicate]

You have to store the timer id of the interval when you start it, you will use this value later to stop it, using the clearInterval function: $(function () { var timerId = 0; $(‘textarea’).focus(function () { timerId = setInterval(function () { // interval function body }, 1000); }); $(‘textarea’).blur(function () { clearInterval(timerId); }); });

How to make `setInterval` behave more in sync, or how to use `setTimeout` instead?

You can create a setTimeout loop using recursion: function timeout() { setTimeout(function () { // Do Something Here // Then recall the parent function to // create a recursive loop. timeout(); }, 1000); } The problem with setInterval() and setTimeout() is that there is no guarantee your code will run in the specified time. By … Read more