Member-only story
Event Loop in JavaScript: How JavaScript Works Under the Hood
JavaScript is a single-threaded language. In other words, it can do only one thing at a time. JavaScript executes all operations on a single thread, but using a few smart data structures, gives us the illusion of multi-threading. The event loop is the secret behind JavaScript’s asynchronous programming.

JavaScript engine executes a script from the top and works its way down creating execution contexts and pushing and popping functions onto and off the call stack.

Behind the Scenes — How does the magic happen..!!
Javascript has a few interesting data structures that help it in appearing like a multi-threaded language.
1 — Call Stack
As the execution proceeds line by line, the method calls are pushed onto the call stack in order of execution. Once the execution is complete, the method is popped from the stack.

2 — Memory Heap