Are you learning JavaScript and trying to understand asynchronous programming? Are you currently a JavaScript programmer who needs an overview of the asynchronous features of JavaScript? Or are you trying to decide which asynchronous technique best suits a programming task you’re trying to accomplish?

If you identify with any of these descriptions — or even if you’re just looking for a refresher on a specific asynchronous technique — the Asynchronous JavaScript series here on the Twilio blog can help. The series covers everything from callbacks to the async and await keywords; and it even includes RxJS Observables, a widely-used external library for handling asynchronous tasks.

Each of the posts includes complete source code for a runnable Node.js project demonstrating the technique covered in the post, and the posts are unified by a common case study so you can compare different approaches to the same task. The code for each post is also available on GitHub under an MIT license so you can download it and use it in your own projects.

Introducing the Asynchronous JavaScript programming tutorials

Here’s a summary of the posts in the series along with a link to each post.

Asynchronous JavaScript: Understanding Callbacks

If you’re new to JavaScript asynchronous programming, start with this post: it covers the JavaScript event loop, events, and callbacks, and other fundamental aspects of JavaScript that have a role in asynchronous programming the JavaScript way. In addition to code you can run to see these language features in action, there are also some nifty animations to help you get a handle on the event loop sequence of events.

Asynchronous JavaScript: Organizing Callbacks for Readability and Reusability

If you’ve been programming for any length of time you’ve likely had to refactor some code. In JavaScript, refactoring nested callbacks is likely to improve the readability of the code and make it easier to maintain and debug. This post builds on the case study introduced in the first post in the series to show you how you can improve the structure of callback code. It also points out aspects of callbacks that should be marked for additional refactoring.

Asynchronous JavaScript: Introduction to JavaScript Promises

Promises are the most powerful asynchronous capability that’s built into the language itself. They offer a number of advantages over callbacks and are a powerful and flexible approach to handling asynchronous tasks. They can be used to wrap callbacks and they’re used as the return type by many REST APIs. Promises are an essential part addition to your JavaScript toolkit. To guide you through the sequence of events that happen in Promise execution there are some nifty diagrams. There’s also a section on handling things when they don’t go the way you expect them to: Promise rejections and exceptions are important aspects of this language feature.

#code #tutorials and hacks #javascript

Asynchronous JavaScript: A Comprehensive Guide
5.65 GEEK