Since js is single-threaded, are the functions executed in setTimeout concurrent? Whether it will affect the thread in progress

setTimeout( ()=>console.log(""), 1000);
function sayHello( arg ) {
    return new Promise ( (resolve, reject) => {
        if( arg === "success" ) {
            for( var i=0; i< 1000; iPP) {
                if(i===999)
                    resolve(i);
            }
        } else if( arg === "fail" ) {
            reject("");
        }
    })
}
console.log("");
sayHello( "success" ).then( arg => {
    console.log(arg)
})

I can"t quite understand this function all the time

if setTimeout has a shorter time setting, will it affect the for loop in Promise?

if setTimeout, is set, are the functions executed in this function executed concurrently?

Oct.25,2021

there is no concurrent execution, and the time you set to run at most in the next cycle is


. The time of setTimeout is not necessarily accurate. Will execute


after for maybe you need to understand the js execution mechanism
portal:
;
if helpful, please adopt

Menu