-
-
Save Knighton910/f66cc7d1c0e67445dcd0517ce530547b to your computer and use it in GitHub Desktop.
Async/Await example
This file contains hidden or 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); | |
}); | |
async function getPosts() { | |
try { | |
const response = await fetch("https://jsonplaceholder.typicode.com/posts"); | |
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