Async & Browser JS / Promises
Promises
A placeholder for a value that isn't ready yet — pending, then settled once, either fulfilled or rejected.
A Promise represents a value that will exist eventually. It starts `pending`, and settles exactly once — either into `fulfilled` (with a value) or `rejected` (with a reason), and can never change state again after that. `.then()` attaches a callback for fulfillment, `.catch()` for rejection, and `.finally()` runs regardless of outcome. Chaining `.then()` calls works because each one returns a new promise.
Codeeditable — Run executes your edits
Loading...
Console
Output will appear here
Visualization
Promise State
PENDING
FULFILLED
REJECTED
Why?
The promise stays pending until the timer inside it fires and calls resolve. Only then does it settle into fulfilled, which triggers the .then callback — never .catch, since it wasn't rejected.