js timer code example
Example 1: timeout javascript
setTimeout(function(){
}, 2000);
Example 2: javascript set delay
var delayInMilliseconds = 1000;
setTimeout(function() {
}, delayInMilliseconds);
Example 3: how to wait in javascript
function pause(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
pause(1000)
Example 4: js wait for time
function sleep(milliseconds) {
const start = Date.now();
while (Date.now() - start < milliseconds);
}
console.log("Hello");
sleep(2000);
console.log("World!");
Example 5: timer in javascript
var timeout = setTimeout(function(){yourFunction()},10000);
var interval = setInterval(function(){yourFunction()},1000);
Example 6: javascipt delay
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
console.log("Hello");
sleep(2000).then(() => { console.log("World!"); });