Example 1 — Example
Core idea.
JavaScript
Promise.resolve(1)
.then((n) => n + 1)
.then((n) => console.log(n));How It Works
- resolve. Already fulfilled.
- then chain. Transforms the value.
A Promise represents a future value: pending, fulfilled, or rejected. Prefer then/catch or async/await over nested callbacks.
Promise.resolve(1)
.then((n) => n + 1)
.then((n) => console.log(n));Core idea.
Promise.resolve(1)
.then((n) => n + 1)
.then((n) => console.log(n));CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful