Promise Chaining Lab
Medium
0.0% Acceptance
In this lab, you will be working on creating and chaining promises. Promises play an important role in JavaScript for handling asynchronous operations like API calls, timers and file operations. A Promise
is an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value. A Promise
is in one of the 3 states:
- Pending: The initial state, neither fulfilled nor rejected.
- Fulfilled: The operation completed successfully, and the promise has a resulting value.
- Rejected: The operation failed, and the promise has a reason for the failure.
You will be given a set of tasks that focus on creating and chaining promises. The main goals are to understand how to create a basic promise, chain promises using .then()
and .catch()
methods, use the async/await
syntax to handle promises, and properly handle errors using a try/catch
block.
Challenges
- Create a basic promise that resolves with a string value.
- Chain a
.then()
method to a promise. - Chain a
.catch()
method to a promise. - Combine both
.then()
and.catch()
methods for error handling. - Use
async/await
to handle a promise. - Handle errors using a
try/catch
block withasync/await
.