timer javascript code example
Example 1: javascript set delay
var delayInMilliseconds = 1000;
setTimeout(function() {
}, delayInMilliseconds);
Example 2: delay in javascript
setTimeout(function() {
}, 1000);
Example 3: 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 4: settimeout
setTimeout(() => {
}, 5000);
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!"); });