Skip to content

Instantly share code, notes, and snippets.

@Karan-Palan
Created December 22, 2023 11:54
Show Gist options
  • Save Karan-Palan/dc077c6b32750f528d1e251bbf10b8cb to your computer and use it in GitHub Desktop.
Save Karan-Palan/dc077c6b32750f528d1e251bbf10b8cb to your computer and use it in GitHub Desktop.
AsyncAwait
// Real world usecase of Async await
const API_URL = "https://api.github.com/users/Karan-Palan"
async function handlePromise() {
const data = await fetch(API_URL);
const jsonValue = await data.json()
console.log(jsonValue);
// fetch - response.json() - jsonValue
}
handlePromise().catch(err => console.log(err));
// Async wait VS Promise.then() -- async await is a syntactical sugar over Promise.then()
// You don't have to do alot of promise chaining for async and await
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment