Writing asynchronous code

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 ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.