1. Create a promise
A Promise wraps an async result; the executor gets resolve and reject callbacks.
new Promise((resolve, reject) => {Typorithm · medium
Step 1 of 8 · intro card
Async
A Promise represents a future value in one of three states: pending, fulfilled, or rejected. then handles success, catch handles errors, and Promise.all waits for several promises at once.
A Promise is an object representing a value that may not be ready yet. It starts pending and settles exactly once into fulfilled (resolve was called) or rejected (reject was called).
then registers a callback for the fulfilled value and returns a new promise, so calls chain: p.then(...).then(...).catch(...). catch handles a rejection anywhere earlier in the chain.
Promise.all([a, b]) takes an array of promises and fulfills with an array of their results once all settle successfully; it rejects immediately if any input rejects.
A promise is pending, fulfilled, or rejected.
then handles success and returns a new promise for chaining.
Promise.all waits for an array of promises.
const p = new Promise((resolve, reject) => {
resolve(42);
});
p.then((v) => v * 2).catch((e) => console.error(e));
Promise.all([a, b]).then(([ra, rb]) => ra + rb);Connect each part of the code to the concept before you type.
A Promise wraps an async result; the executor gets resolve and reject callbacks.
new Promise((resolve, reject) => {Calling resolve moves the promise from pending to fulfilled with the value 42.
resolve(42);then runs when the promise fulfills and returns a new promise for chaining.
p.then((v) => v * 2)catch runs if any earlier step rejects, handling the error in the chain.
.catch((e) => console.error(e))Promise.all waits for every promise to fulfill, or rejects as soon as one does.
Promise.all([a, b])Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.