Node.js
/Intermediate
Promises
Definition
An object representing the eventual completion (or failure) of an asynchronous operation and its resulting value. It cures Callback Hell by allowing asynchronous methods to be chained.
Explain Like I'm New
A Promise is a restaurant buzzer. You order food, and they give you a physical buzzer object. It sits in your hand in a 'Pending' state. You can keep talking with your friends. Eventually, the buzzer either flashes green ('Resolved' - here is your food) or flashes red ('Rejected' - we ran out of ingredients).
Real World Example
Modern database drivers and the `fetch` API all return Promises. You attach `.then()` to handle success, and `.catch()` to handle errors cleanly in one place.
Common Use Cases
- •Modern asynchronous flow control
- •Fetching APIs
- •Chaining dependent async tasks
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- What are the three states of a Promise?
intermediate
- How does chaining `.then()` solve Callback Hell?
advanced
- What does `Promise.all()` do?