Search⌘ K

JavaScript Execution: Call Stack & Event Loop

Explore how JavaScript executes code using the call stack, event loop, and event queue. Learn the relationship between synchronous and asynchronous code including setTimeout, to strengthen your understanding for JavaScript coding interviews.

We'll cover the following...

Let’s go over some important and commonly tested concepts of JavaScript during interviews. This includes the working of the call stack, web API, and event queue.

setTimeout #

JavaScript is single-threaded, meaning it can only run one command at a time. Due to this, commands are not run in parallel. Because the execution happens line-by-line, each command is considered synchronous hence blocking.

So, is it possible to run an asynchronous code in JavaScript?

This is where the setTimeout function comes into play. It is a web API provided by the browser that takes a callback function as its first parameter and time in milliseconds as its second parameter. It executes the callback function after the ...