Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

async vs await javascript

async function myFetch() {
  let response = await fetch('coffee.jpg');

  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }

  let myBlob = await response.blob();

  let objectURL = URL.createObjectURL(myBlob);
  let image = document.createElement('img');
  image.src = objectURL;
  document.body.appendChild(image);
  }
}

myFetch()
.catch(e => {
  console.log('There has been a problem with your fetch operation: ' + e.message);
});
Comment

async vs await javascript

fetch('coffee.jpg')
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return response.blob();
})
.then(myBlob => {
  let objectURL = URL.createObjectURL(myBlob);
  let image = document.createElement('img');
  image.src = objectURL;
  document.body.appendChild(image);
})
.catch(e => {
  console.log('There has been a problem with your fetch operation: ' + e.message);
});
Comment

async vs await javascript

async function myFetch() {
  let response = await fetch('coffee.jpg');
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return await response.blob();

}

myFetch().then((blob) => {
  let objectURL = URL.createObjectURL(blob);
  let image = document.createElement('img');
  image.src = objectURL;
  document.body.appendChild(image);
}).catch(e => console.log(e));
Comment

PREVIOUS NEXT
Code Example
Javascript :: check items in array javascript 
Javascript :: lettre au hasard javascript 
Javascript :: objects in javascript 
Javascript :: ex:javascript 
Javascript :: set timer 
Javascript :: nginx location regex * 
Javascript :: react lifecycle hooks 
Javascript :: javascript null 
Javascript :: date formatting javascript 
Javascript :: how to declare 3d array in javascript 
Javascript :: Plugin "react" was conflicted between "package.json » eslint-config-react-app 
Javascript :: add event listeners 
Javascript :: open source code 
Javascript :: get x y z position of mouse javascript 
Javascript :: how to generate a random number between certain values 
Javascript :: js.l6 
Javascript :: node.js server-side javascript 
Javascript :: mongoose fails to connect to server when database is specified 
Javascript :: MERN stack implementing Sign in with Google. 
Javascript :: how to set direction based on language in angular 
Javascript :: When an aqueous solution of AgNO3 is mixed with an aqueous solution of (NH4)2CrO4, a precipitation reaction occurs. For this reaction, a) Write the molecular equation. 
Javascript :: jquery to javascript converter online 
Javascript :: print array list to a ul list 
Javascript :: await zoomus.joinmeeting crashing app react native 
Javascript :: missing data added between two points javascript 
Javascript :: npm can i use my modules without specifying the path 
Javascript :: passportjs mac req.user not saved 
Javascript :: var test 
Javascript :: one-page web app that requires simple style work. using html, css,javascript and jquery 
Javascript :: get current page rows in tabulator js 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =