Since its beginning as a primitive, unstandardized scripting language for web browsers, JavaScript has gained many features that better equip it for handling common programming tasks. Some of the most important improvements are in the area of handling asynchronous events like form submission, user interface interaction, and media management.

The growth of server-side JavaScript enabled by Node.js has substantially expanded the range of project types and business challenges JavaScript can successfully address, adding new requirements for asynchronous processing. The popularity of web services as a design paradigm and REST APIs as an interaction standard have both added to the scope of asynchronous tasks for the language.

The Node package management system, npm, makes it possible to easily integrate capabilities provided in open source libraries. Packages for asynchronous tasks have been some of the most successful of these, adding programming paradigms to JavaScript that were unimagined in the early days of the language.

With this surfeit of tools developers can sometimes be left wondering which tool is best suited to a specific task. Programming challenges don’t always fit neatly into the abstract patterns described in documentation, so it’s helpful to have a way of understanding the strengths and weaknesses of each tool, and a way of processing the questions that will lead to the right choice.

This post provides a summary of the four principal asynchronous techniques in JavaScript programming, identifying the common use cases for each technique and the pros and cons of each tool. Each summary includes links to in-depth information and tutorials provided in other posts in this Asynchronous JavaScript series.

This post also provides a decision tree you can use to identify the asynchronous tool that’s best suited to a specific task. By answering a few straightforward questions about your programming task you can quickly find a recommendation. You’ll also learn more about the factors that determine the suitability of each tool to specific programming challenges.

It’s important to understand that while the JavaScript keywords, object types, and libraries that provide asynchronous functionality are tools in your programming workshop, they’re also the basis for programming techniques. Each tool is best wielded in specific ways, so understanding the best ways to use these technologies is as important as understanding how they work.

Callbacks

Callback is a function passed to another function as an argument. The function receiving the Callback executes code in the background and uses the Callback function to notify the calling function when its work is done.

Typical tasks for callbacks are reading a file from disk or performing a REST API call. Callbacks can be also used to listen for events such as user interface interaction and changes in the file system.

Although using Callbacks in new code isn’t popular, they’re still a part of many foundational JavaScript libraries.

#code #tutorials and hacks #python #javascipt

Asynchronous JavaScript: Choosing the Right Asynchronous Tool
1.05 GEEK