javascript time repeat code example
Example 1: jquery call function every second
setInterval(function(){
//this code runs every second
}, 1000);
Example 2: js setinterval
function func(){
console.log("Ran")
}
setInterval(func,1000)//Runs the "func" function every second
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();