Although modern JavaScript brings promises and ES8 brings in async/await (which we'll see soon), still, there will be times when you'll encounter old APIs using callback mechanism/event-based mechanisms for their asynchronous operations.
It is important to understand the working of older asynchronous coding practices. This is because you cannot convert a callback-based asynchronous code piece to shining promises/async-await-based code without actually understanding how it works!
JavaScript, earlier, natively supported two patterns for writing asynchronous code, that is, the event pattern and the callback pattern. While writing asynchronous code, we usually start an asynchronous operation and register the event handlers or pass the callbacks, which will be executed once the operation is finished.
Event handlers or callbacks are used, depending...