Answers for "javascript stop execution for seconds"

3

javascript wait 1 second

setTimeout(function(){ 
    console.log("Ready")
}, 1000);
Posted by: Guest on November-11-2020
1

sleep js

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function demo() {
  console.log('Taking a break...');
  await sleep(2000);
  console.log('Two seconds later, showing sleep in a loop...');

  // Sleep in loop
  for (let i = 0; i < 5; i++) {
    if (i === 3)
      await sleep(2000);
    console.log(i);
  }
}

demo();
Posted by: Guest on December-31-2020

Code answers related to "javascript stop execution for seconds"

Code answers related to "Javascript"

Browse Popular Code Answers by Language