As most developers are aware, Javascript
is single-threaded, which means that two JavaScript statements cannot be excluded at the same time. Because execution occurs line by line, each JavaScript statement is synchronous and blocking, but there is a way to run your code asynchronously by usingsetTimeout ()
.
The event loop is responsible for node.js's ability to perform nonblocking I/O operations.
An example of this as we have said is setTimeout ()
.
setTimeout(function(){...}, 0)
Simply queues the code for execution once the current call stack has completed. This can be useful in some situations. So, while it is asynchronous in the sense that it interrupts the synchronous flow, it will not execute concurrently/on a separate thread.
Top comments (0)