🧭Promise (JavaScript)
Also known as Promise, Future, Promises
An object for a result not ready yet. It ends in a value or an error.
Think of it like
Think of it like a ticket at a coat check. It is not your coat yet, but you will get it back.
Example
Lucy's app calls fetch for a weather page. It gets a promise at once, and the forecast shows up when the promise is fulfilled.
Why it matters
Definition
Example code
javascript
Promise.resolve(5).then((n) => console.log(n * 2)); // 10Common mistake
Key takeaways
- 1A value to come. Not ready yet.
- 2Three states. Pending, fulfilled, rejected.
- 3Chain with then. Steps read in order.