Using Fetch with async and await

 let url = "https://catfact.ninja/fact";


async function getFacts() {
  try {
    let res = await fetch(url);
    let data = await res.json();
    console.log(data.fact);

    let res2 = await fetch(url);
    let data2 = await res2.json();
    console.log(data2.fact);
  } catch (e) {
    console.log(e);
  }
  console.log("TQ");
}

console.log(getFacts());

Comments

Popular posts from this blog

Callback Hell

TODO list with DOM

Refactoring callback hell code