Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Created October 15, 2017 09:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save coryhouse/68db344b82b51b99b1063ba9e5071d0e to your computer and use it in GitHub Desktop.
Save coryhouse/68db344b82b51b99b1063ba9e5071d0e to your computer and use it in GitHub Desktop.
Async/Await example
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