Asynchronous JavaScript

This page is not complete.

In this module we take a look at asynchronous JavaScript, why it is important, and how it can be used to effectively handle potential blocking operations such as fetching resources from a server or processor-intensive calculations.


Asynchronous JavaScript is a fairly advanced topic, and you are advised to work through JavaScript first steps and JavaScript building blocks before attempting this.

Note: If you are working on a computer/tablet/other device where you don't have the ability to create your own files, you could try out (most of) the code examples in an online coding program such as JSBin or Thimble.


Introducing async JavaScript
In the first article of this module we look at what synchronous and asynchronous code are (sync and async), and how they differ. We'll also examine traditional sync methods of handling a sequence of operations, see what the problems are, and begin to understand how async techniques can help us solve such problems.
Async loops and intervals
Here we look at the traditional methods JavaScript has available for running code asychronously after a set time period has elapsed, or at a regular interval (e.g. once per second), talk about what they are useful for, and look at their inherent issues.
Handling async operations gracefully with Promises
Promises are a comparitively new feature of the JavaScript language that allow you to defer further actions until after the previous action has completed, or respond to its failure. This is really useful for setting up a sequence of operations to work correctly. This article shows you how promises work, where you'll see them in use in WebAPIs, and how to write your own.
Easier async code with async and await
Promises can be somewhat complex to set up and understand, and so modern browsers have implemented async functions and the await operator — the former allows standard functions to implicitly behave asynchronously with promises, whereas the latter can be used inside async functions to wait for promises before the function continues, making chaining  of promises easier. This article explains async/await.



See also

Document Tags and Contributors

Contributors to this page: chrisdavidmills
Last updated by: chrisdavidmills,