settimeout and setinterval example
Example 1: difference between setTimeout() and setInterval()
.setTimeout()
.setInterval()
Example 2: javascript set timeout
var timeToWait = 3000;
setTimeout(() => {
console.log("Text printed after 3 seconds");
}, timeToWait);
Example 3: javascipt delay
async function delay(delayInms) {
return new Promise(resolve => {
setTimeout(() => {
resolve(2);
}, delayInms);
});
}
async function sample() {
console.log('a');
console.log('waiting...')
let delayres = await delay(3000);
console.log('b');
}
sample();