Can setTimeout execute more than one?

for example:

    setTimeout(function(){
            $(".abc").removeClass("a");
        },5000);
    setTimeout(function(){
            $(".abc").removeClass("b");
        },3000);
        
The

requirement is that if the second setTimeout is executed before the first setTimeout is executed, will the first setTimeout be overwritten? If so, is there any other way? Thank you!


is not overwritten, they are two anonymous asynchronous executions, and each has its own scope


there are no overrides. In general, the execution order is first arranged according to the time parameters given by the timer, and if the time is the same, it is arranged in the order of the code statements.


each execution does not understand what you are trying to say


run

after 3 seconds
removeClass ('b')

wait another two seconds

removeClass ('a')

related issues relate to async .


Brother, the first time parameter of your two timeout calls is different, so there is no coverage problem. Secondly, the event module of js is asynchronous.

Menu