# Nested Callbacks
JS can handle callbacks.
When your application grows more complex, you can have callbacks in callbacks in callbacks...
hard to read and hard to understand -› callback hell
Tip: Using callbacks can be quite "messy" This problem is commonly known as "callback hell". This problem can be reduced by good coding practices (see http://callbackhell.com/), using a module like async (opens new window), or moving to ES6 features like Promises (opens new window).
Note: A common convention for Node and Express is to use error-first callbacks: the first value in your callback functions is an error value, while subsequent arguments contain success data. good explanation: The Node.js Way - Understanding Error-First Callbacks (opens new window) (fredkschott.com).
MDN Using asynchronous APIs (opens new window)
Using callbacks is slightly old-fashioned now, but you'll still see them in use in a number of older-but-still-commonly-used APIs.
btn.addEventListener('click', () => {
alert('You clicked me!');
let pElem = document.createElement('p');
pElem.textContent = 'This is a newly-added paragraph.';
document.body.appendChild(pElem);
});
Note that not all callbacks are async — some run synchronously. An example is when we use Array.prototype.forEach()
(opens new window)
Better to use Promises