Suppose an AJAX request is loading a user’s organizations. How do you use the response without knowing when it will arrive? The request returns a promise, and `.then()` registers a callback to receive its eventual value. If the promise is still pending, the callback waits; if it has already resolved, the callback still runs, but through the event loop rather than immediately. section 30.0 section 30.1
Use a completed request
```js axios.get('https://api.github.com/users/jisaacks/orgs') .then(resp => { const orgs = resp.data; // use the organizations }); ``` First, `axios.get` starts the request and returns a promise. Calling `.then()` supplies the function that will receive the response after the request succeeds. The organizations are read from that response, not from the promise itself. section 30.1
A promise can have `.then()` called on it more than once. That makes it useful when loading starts before the result is needed: a user view can start fetching organizations in its constructor, then call `.then()` when it is time to display them. The display step works whether loading has finished or is still underway. section 30.1 section 30.4
Handle either result
```js axios.get(url).then(handleResp, handleError); ``` The first callback handles a successful response. The optional second callback receives an error when the promise is rejected. For a quick check, take a callback-based `getJSON` call that receives `(err, json)` and rewrite its success and error branches as these two `.then()` callbacks. section 30.2
Each call to `.then()` returns a new promise, so calls can form a chain. `.catch(errCatcher)` is shorthand for `.then(null, errCatcher)`; responses and rejections can move through that chain. For an already available value, `Promise.resolve(value)` provides a resolved promise that can still be used with `.then()`—handy when a function should return a promise for both cached and newly loaded data. section 31.4 section 30.3




