Intro

In its most basic form, Javascript is a synchronous, blocking, single-threaded language.

Just javascript is not enough to cater to asynchronous programming.

Web browsers help us with this. They define functions and APIs that allow us to register functions that should not be executed synchronously and should be invoked asynchronously when some kind of event occurs.

E.g passage of time (setInterval or setTimeout), user interaction with the mouse (addEventListener), or the arrival of data over the network (callback, Promises, async-await).

Timeouts and Intervals

These are not part of JS, the browser implements them - setTimeout()and setInterval() are names given to that functionality in Javascript.

setTimeout(function,duration, params*) - executes a particular block of code once after a specified time has elapsed.

setInterval(function, duration, params*) - repeatedly runs the same code over and over again, at set intervals.

Note: