DEV Community


Posted on

is JavaScript a multi-threading or single-threading ?

let's discus most confused topics in JavaScript, it's 'event loop' or is JavaScript a multi-threading or single-threading ?

the secret behind JavaScript’s asynchronous programming is event loop,  JS executes all operations on a single thread, but using a few smart data structures, it gives us the illusion of multi-threading. Let’s take a look at what happens on the back-end.

The event queue is responsible for sending new functions to the track for processing. It follows the queue data structure to maintain the correct sequence in which all operations should be sent for execution.

The event queue. Hence, we have a cyclic system for running async operations in JavaScript. The language itself is single-threaded, but the browser APIs act as separate threads.

The event loop facilitates this process; it constantly checks whether or not the call stack is empty. If it is empty, new functions are added from the event queue. If it is not, then the current function call is processed.

Top comments (1)

haguezoum profile image
Hassan Aguezoum

hmmm thank you , if you can add some pictures to expline more this prosses between Queue and the track . Thank you again <3