JavaScript is a language designed to run client-side. It has affected not only the design of the language itself, but also the way its runtime environments are structured: browsers, Node.js, and others.
Browsers are designed for the so-called event-driven model. In this model, code isn't executing continuously. It waits for user events, like button presses, mouse clicks, or scrolling.
Each of these events and dozens of others triggers the necessary handler. Every handler has special requirements: it shouldn't stop anything, because one event can cause many things almost in parallel. In other words, the user should be able to continue interacting with the interface.
For these reasons, all engines and JavaScript code executables rely on an asynchronous model. In this model, any input/output operations perform asynchronously.
Asynchronous code is wholly different from synchronous code and takes time to get used to it. It has a different way of handling errors and a different approach to writing code. Adding some features creates problems in other places: what was easy to do in synchronous code may be difficult in asynchronous code. It is the price we pay for performance.
Asynchronous programming in JavaScript has gone through several stages: from collabs and promises to the async/await concept.
These approaches are important in their way, and we will discuss them in this course. In the end, you'll learn how to write modern, efficient, and understandable code with the advantages of asynchronous code. It will be almost as good as synchronous code in terms of clarity and simplicity.
The main topics of this course are:
- Asynchronous IO
- Error handling
- Event Loop
- Timers
- Promises
- Async/Await
- EventEmitter
Preparation
In this course, we study asynchrony, one of the most crucial things in JavaScript.
To understand it, you need a good command of basic programming language syntax, higher-order functions, HTTP, and working with collections. We cover these topics in our other JavaScript courses.
You can find the correct sequence of courses in the profession Frontend Programmer.
Are there any more questions? Ask them in the Discussion section.
The Hexlet support team or other students will answer you.
For full access to the course you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.