JavaScript gets executed by a single thread. According to this, it is advisable to avoid long-lasting operations in the first place. What we are going to do if callbacks are omnipresent?

Whenever it comes to I/O-operations, like a network or a file system, then this circumstance can get quite heavy. Fortunately, there are two kinds of callbacks in JavaScript. Want to take a really deep dive into this? Havoc’s Blog [1] did a pretty detailed investigation about that. The base difference between synchronous and asynchronous callbacks is: Synchronous callbacks are getting executed in the calling’s context method, whereas asynchronous not.

A good example is to flatten an array of arrays. When this function gets executed, the passed-in parameter will be reduced to get rid of the multiple arrays inside an array and convert it into a single flattened one.

#programming #coding #javascript #web-development

Asynchronous vs Synchronous Programming in JavaScript
1.85 GEEK