“Penundaan JavaScript” Kode Jawaban

Tidur Javascript

const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}

/*Use like so*/

async function timeSensativeAction(){ //must be async func
  //do something here
  await sleep(5000) //wait 5 seconds
  //continue on...
}
Energetic Eagle

keterlambatan dalam javascript

setTimeout(function() {
 //your code here
}, 1000);
Tender Toad

JavaScript tunggu 1 detik

  setTimeout(function(){ 
    console.log("Ready")
}, 1000);
Foreverekk

Tidur Javascript

function sleep(milliseconds) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < milliseconds);
}

console.log("Hello");
sleep(2000);
console.log("World!");
VahidTheGreat

tunggu javascript waktu

//code before the pause
setTimeout(function(){
    //do what you need here
}, 2000);
PutterBeanut

Penundaan JavaScript

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

console.log("Hello");
sleep(2000).then(() => { console.log("World!"); });
Witty Worm

Jawaban yang mirip dengan “Penundaan JavaScript”

Pertanyaan yang mirip dengan “Penundaan JavaScript”

Lebih banyak jawaban terkait untuk “Penundaan JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya