Last active
May 1, 2019 08:55
-
-
Save coryhouse/aba7dad068e8c1bb5eeb04facd50ef98 to your computer and use it in GitHub Desktop.
Promise example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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