setTimeout() and setInterval()

setTimeout(f,delay[, p 1[ p 2[,...]]) executes the function f(p1,p2...) once after 'delay' milliseconds. Notice the asynchrony. As the time is reached, a task is added to the macrotask queue.


RESETRUNFULL
<!DOCTYPE html><html><body><script>

setTimeout(()=>{console.log(1000);},1000); console.log(1);setTimeout(()=>{console.log(200);},200);
    console.log(2);setTimeout(()=>{console.log(500);},500);
    console.log(3);// 1,2,3,200,500,1000

</script></body><html>

set Interval (f, interval [, p 1[, p 2[,...]]) calls the function f(p1,p2...) repeatedly every 'interval' milliseconds. The first call begins only after interval milliseconds.

setTimeout() and setInterval() can be stopped by calling clearTimeout() and clearInterval() respectively.
RESETRUNFULL
<!DOCTYPE html><html><body><script>

var n=0;var intervalID = setInterval((a,b)=>{
   n++;
   if (n>b) clearInterval(intervalID);
   if (n>=a) console.log(n+ ' seconds have lapsed.');},1000,5,7);// 5 seconds have lapsed.// 6 seconds have lapsed.// 7 seconds have lapsed.// 8 seconds have lapsed.

</script></body><html>