“JavaScript tidur 1 detik” Kode Jawaban

JavaScript tidur 1 detik

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

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

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

JavaScript tidur 1 detik

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

JavaScript tidur 1 detik

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

async function test() {
  console.log('start timer');
  await delay(1000);
  console.log('after 1 second');
}

test();
MorbidMeta

JavaScript tidur 1 detik

import time
def time_sleep ( sec=1.0 ):
  time.sleep( sec )
  return
Jirayu Kaewprateep

JavaScript tidur 1 detik

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

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

JavaScript tidur 1 detik

# this is just a trial of adding answers with Grepper
Mohieddine Farid

JavaScript tidur 1 detik

setTimeout(myFunction, 3000);

// if you have defined a function named myFunction 
// it will run after 3 seconds (3000 milliseconds)
function test1()
{    
    // let's say JavaScript did have a sleep function..
    // sleep for 3 seconds
    sleep(3000);

    alert('hi'); 
}
Kalyani Sree Selvaganesan

JavaScript tidur 1 detik

// `sleep' function from @Clever Cheetah
function sleep(delay) {
    let start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}

sleep(1000);
console.log("Do something")
Tame Tern

JavaScript tidur 1 detik

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

delay(1000).then(() => console.log('ran after 1 second passed'));
Davin Leo

Jawaban yang mirip dengan “JavaScript tidur 1 detik”

Pertanyaan yang mirip dengan “JavaScript tidur 1 detik”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya