“JS tidur 1 detik” Kode Jawaban

JavaScript tidur selama 1 detik

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

delay(1000).then(() => console.log('ran after 1 second1 passed'));
Powerful Puma

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

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

JavaScript tidur 1 detik

async function test() {
  console.log('start timer');
  await new Promise(resolve => setTimeout(resolve, 1000));
  console.log('after 1 second');
}

test();
Clear Cat

JS tidur 1 detik

await new Promise(resolve => setTimeout(resolve, milliseconds))
xXjojaXx

JS tidur 1 detik

setTimeout(myFunction, 3000);
Jonathan Diego Susanto

Jawaban yang mirip dengan “JS tidur 1 detik”

Pertanyaan yang mirip dengan “JS tidur 1 detik”

Lebih banyak jawaban terkait untuk “JS tidur 1 detik” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya