Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Last active May 1, 2019 08:55
Show Gist options
  • Save coryhouse/aba7dad068e8c1bb5eeb04facd50ef98 to your computer and use it in GitHub Desktop.
Save coryhouse/aba7dad068e8c1bb5eeb04facd50ef98 to your computer and use it in GitHub Desktop.
Promise example
getPosts().then( posts => {
console.log(posts.length);
});
function getPosts() {
return fetch("https://jsonplaceholder.typicode.com/posts")
.then(response => {
return response.json();
})
.catch( error => console.log(error));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment