0

I know the output of the code but can anyone please tell me when setTimeout will be called please...

function delay(time) {
    
    return new Promise(function (resolve) {
        setTimeout(() => {
            resolve();            
        }, time);
    })
}


delay(3000).then(function () {
    console.log("run after 3000 seconds")
})
so_hell
  • 41
  • 5
  • After approximately 3000ms? (so 3 not 3000 seconds). Not really sure what you're asking please clarify your question. – Benjamin Gruenbaum Feb 28 '22 at 15:02
  • `setTimeout(…)` is called immediately (from within `delay(…)`). `resolve()` is called 3 seconds after that. What exactly is unclear? – Bergi Feb 28 '22 at 15:03
  • 3000s is just a typo , I just want to know when the setTimeout will be pushed into the callback queue. 1) when i am returning 2) when i typing .then() – so_hell Feb 28 '22 at 15:04

0 Answers0