Answers for "js then vs await"

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
-1

js then vs await

const a = async () => {	
  	await b();
  	c();
};
Posted by: Guest on May-04-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language