Namaste JavaScript — Interview Quick Notes
Ep 21–22: Promises
- A Promise is an object that is a placeholder for a future async value. States: pending → fulfilled or rejected.
- Promise result is immutable once settled — safe to pass around.
- .then attaches a success callback; .catch handles rejection; both return promises enabling chaining.
- Always return a value/promise inside .then to pass data down the chain.
- .catch placed mid-chain only catches errors from above it; code below it still runs.
1createOrder(cart)
2 .then((orderId) => proceedToPayment(orderId))
3 .then((info) => showOrderSummary(info))
4 .catch((err) => console.error(err))