The problem of execution order between promise and setimeout

const promise = new Promise((resolve, reject) => {
    console.log(1);
    resolve();
    console.log(2);
    setTimeout(()=>{
      console.log(7);
    })
});
promise.then(() => {
    console.log(3);
    setTimeout(()=>{
      console.log(6);
    })
});
setTimeout(()=>{
  console.log(5);
})
console.log(4);
Apr.21,2022

setTimeout (fn, 0) is executed at the beginning of the next event loop, and Promise.then () is executed at the end of the current event loop.


if called immediately, promise executes first, then setTimeout executes

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ab3d-2c240.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ab3d-2c240.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?