JavaScript is a single-threaded programming language. Considering this it is very important that you understand the behavior of asynchronous code. There are three important techniques for writing asynchronous code in JavaScript:
- Callbacks
- Promises
- Async / Await
For understanding asynchronous JavaScript in general read Understanding Asynchronous JavaScript .
A callback is a function that is to be executed after another function has finished executing. Read JavaScript: What the heck is a Callback?.
For understanding promises read A Simple Guide to ES6 Promises. For more information about promises and good practices read Master the JavaScript Interview: What is a Promise?. It is important that you know the prototype methods .then
, .catch
and the functions available from Promise: Promise.all
and Promise.race
.
The article How to escape async/await hell points out the correct usage of async/await and how you can avoid common pitfalls.