Skip to main content

Callback Hell

Before jumping into the topic of this blog I'm going to first talk about how it came to existence in the first place. While developing applications (web in general) and especially on the backend, we always face that need to make asynchronous calls to do stuff once others finish. And to solve this issue developers usually used nested functions also known by callbacks. While it solved the problem it still caused what is known by callback hell.

Image result for callback hell

Callbacks don't scale and are not good practice as far as I know. We can fix this issue and write better and readable code that works asynchronously but looks synchronous with the use of promises.

Comments

Popular posts from this blog

Stack vs. Queue

Stack is like a pile of  books placed on top of each other. We can add new books to the top and can remove them from only the top because stacks are LIFO which means last-in, first-out. Queues on the other hand are the opposite, which is FIFO meaning first-in, first-out. So adding an element to the queue will be the same but removing will happen to the first element not the last one. An example of a queue would be the wait line in front of any kind of service we see around us like the bus station or the shops,....etc.

Middlewares

Middlewares in Javascript are functions that come in the middle of the request-response cycle. They have access to both the request and the response object as well as the next middleware function to be executed; usually called next(). Popular examples on middleware include: body-parser, cors, session, cookie-seesion and cookie-parser.