Answers for "async await vs then"

0

async await vs then

async function fancyShowRainbow(){
  const response = await fetch("rainbow.jpg");
  const blob = await response.blob();
  document.querySelector(".my-image").src = URL.createObjectURL(blob);
}


function showRainbow(){
  fetch("rainbow.jpg")
  .then(res => {
    console.log(res);
    return res.blob();
  })
  .then(blob => {
    document.querySelector(".my-image").src = URL.createObjectURL(blob);
    console.log(blob);
  })
  .catch(error => {
    console.log("ERROR!!");
    console.error(error);
  });
}
Posted by: Guest on July-19-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language