Skip to content

Instantly share code, notes, and snippets.

@Knighton910
Forked from coryhouse/async.js
Created September 6, 2019 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Knighton910/f66cc7d1c0e67445dcd0517ce530547b to your computer and use it in GitHub Desktop.
Save Knighton910/f66cc7d1c0e67445dcd0517ce530547b 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