“JavaScript Schlaf für 1 Sekunde” Code-Antworten

JavaScript Schlaf für 1 Sekunde

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

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

JavaScript Schlaf 1 Sekunde

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

test();
Clear Cat

JavaScript -Version des Schlafes

//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
Grepper

JavaScript Schlaf 1 Sekunde

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

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

Warten Sie JavaScript

 wait(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
 }
Graceful Guanaco

JS Schlaf 1 Sekunde

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

Ähnliche Antworten wie “JavaScript Schlaf für 1 Sekunde”

Fragen ähnlich wie “JavaScript Schlaf für 1 Sekunde”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen