Answers for "javascript sleep for 1 second"

5

javascript sleep for 1 second

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

delay(1000).then(() => console.log('ran after 1 second1 passed'));
Posted by: Guest on October-25-2021
5

javascript version of sleep

//Javascipt is asyncronous so you can't pause/block code execution
//You can delay doing something with setTimeout
setTimeout(function(){
 	alert("Sup!"); 
}, 2000);//wait 2 seconds
Posted by: Guest on July-23-2019
10

wait javascript

wait(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
 }
Posted by: Guest on June-19-2020
1

javascript sleep settimeout

setTimeout(() => {  console.log("World!"); }, 2000);
Posted by: Guest on March-13-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language