Skip to content
AgileLogics
5 min read

Promises

A Promise represents a value that isn't ready yet, but will be — the result of an operation that takes time, like a network request.

function delay(ms) {
    return new Promise((resolve) => setTimeout(resolve, ms));
}

delay(1000).then(() => {
    console.log("One second has passed");
});

A Promise is in one of three states: pending (not finished yet), fulfilled (succeeded, .then() runs), or rejected (failed, .catch() runs). async/await, covered next, is generally easier to read than chaining .then() calls directly.