Article From:

In the following code, if I change the interval variable of the return value of setInterval (), what can I do to get the return value of setInterval (…)?
setInterval()Can the return value only be assigned to variables? If this variable is changed, can’t we get rid of the timer?

var num = 0;
var interval = setInterval(function(){
    if(num >= 5){
        interval = null;//Change the interval variable.ClearInterval (interval)};}, 3000);

Answer 0:

Good luck, next execution.setIntervalAcquiredidIt will be 1 more than the previous one, but this is not reliable, because you can not guarantee your two.setIntervalThere is no other.setIntervalHave been executed

Answer 1:

First clear, then change the return value of setInterval.

Answer 2:

The general execution of if condition code is before the business logic code to be executed by the timer.

Leave a Reply

Your email address will not be published. Required fields are marked *