The intention of this exercise is to give you more experience managing asynchronous operations in the browser using JavaScript.
-
Using Visual Studio Code, open the folder
flexpath-async-programming-with-js-exercises
wherever you saved it on your device. -
Then open the
flexpath-async-programming-with-js-exercises/exercise
folder. Inside is a file namedindex.html
. Open this file in your web browser using the methods shown inflexpath-html-and-css-in-depth-exercises
. -
You will write your JavaScript code in
exercise.js
. Any time you make a change, save the file and then refresh the webpage displaying your .html web page in the browser.We have included a video
js-async-web.mp4
showing how to do this.Exercise instructions are provided to you as code comments in the
exercise.js
file.
VIDEO DISCLAIMER - You will need to clone the repo to your local device before you can watch the .mp4 file since GitHub does not support watching it from here.
Exercise solutions are in the /solution
folder
-
Asynchronous Programming:
- Understanding the differences between synchronous and asynchronous code execution.
- Working with callbacks and the challenges they present, such as the callback pyramid of doom.
-
Promises:
- Creating and using Promises in JavaScript.
- Promise states: pending, fulfilled, and rejected.
- Consuming promises using
then
,catch
, andfinally
methods. - Chaining multiple promises for sequential execution.
- Handling errors and understanding how promises handle rejected states.
- Using Promise-based libraries like Axios.
-
Async/Await:
- Simplifying asynchronous code using the
async
andawait
keywords. - Error handling in async functions using try-catch blocks.
- Using async/await for sequential and parallel API requests.
- Combining promises and async/await for more complex asynchronous flows.
- Simplifying asynchronous code using the
-
Advanced Promise Methods:
Promise.all
: Running multiple promises concurrently and waiting for all to complete.Promise.allSettled
: Handling all promises and capturing both resolved and rejected outcomes.Promise.any
: Returning the first resolved promise and handling multiple sources of data.Promise.race
: Handling the first settled promise, whether fulfilled or rejected.
-
HTTP Requests:
- Making HTTP requests using
XMLHttpRequest
and Fetch API. - Handling and configuring HTTP headers and status codes.
- Using AbortController to cancel requests.
- Understanding CORS and preflight requests.
- Making HTTP requests using