Making a counter and Understanding async flow through it

What is a counter?

Counter is simply counting of numbers or time recursively . here we are trying to make a representation of second hand of a clock and thus understand async flow via it.

javascript is an asynchronous language but at the same time it is single-threaded as well, so it uses web APIs and callback queues to handle async functions.

let us rundown though the code once and understand it's flow.

javascript has its way of dealing with async functions, first, it will run down and execute each line till line 5 as an interpreted language does, but as it encounters an async function , it delegates its take to web api to handle it until it has finished its execution of each line till 8.

After js is down with line 8, the web api comes into action and it passes the function to the callback queue.

What is a callback queue?

It handles the workflow of async functions. whichever function gets interpreted by the webapi first will go in the callback queue first, it doesn't matter the sequence in which functions are in web api.

From the callback queue, it goes to the call stack and is thus executed.