From the course: JavaScript: Async

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Appending methods to resolved promises

Appending methods to resolved promises - JavaScript Tutorial

From the course: JavaScript: Async

Appending methods to resolved promises

- So far, our code returns an object from a promise, and that means we're on the right track, but we want to do something with that object. The object returned by a resolve method isn't meant for direct examination. It itself is a promise and requires specific syntax to work with. To handle the object return from a successful promise, we simply append the then method to the promise call. Then expects a promise as an argument and enables you to work with the result data embedded in that object. And you can chain as many then methods as you want. One after another, allowing you to work with data synchronously or asynchronously and hand off the result to another function at each step. And this makes code easier to read, than nested callback sometimes do. In our get function for the Explore California site. We want to dig into the data returned from our HTTP request. So to do that, instead of logging that object to the…

Contents