| 1. |
What is callback hell, and how can it be avoided? |
|
Answer» Callback HELL is a SITUATION in Javascript when you face callbacks within callbacks or nested callbacks. It looks somewhat like this: firstFunction(ARGS, function() { There are two significant ways to avoid Callback Hell in NodeJS: 1. Using Promisesconst makeBurger = () => { SEE, it is just more easy to read and manage in comparison to the nested callbacks. 2. USE Async/AwaitUsing Asynchronous functions, we can convert makeBurger into one synchronous code. Also, maybe you can get helpers to getBun and getChicken at the same time, meaning, you can use await with Promise.all. Here's the code: const makeBurger = async () => { |
|