“JS aguarda” Respostas de código

Awiat assíncrono

const data = async ()  => {
  const got = await fetch('https://jsonplaceholder.typicode.com/todos/1');
  
  console.log(await got.json())
}

data();
Salo Hopeless

JavaScript aguardando

await new Promise(resolve => setTimeout(resolve, 5000)); // 5 second wait

//or

(async () => {
await new Promise(resolve => setTimeout(resolve, 5000)); // 5 second wait
})();
Pudochu

assíncrono aguardando

async function f() {

  try {
    let response = await fetch('/no-user-here');
    let user = await response.json();
  } catch(err) {
    // catches errors both in fetch and response.json
    alert(err);
  }
}

f();
Yawning Yak

Aguarde JavaScript

If the value of the expression following the await operator is not a Promise, it's converted to a resolved Promise.
Smoggy Swiftlet

assíncrono aguardando js

fetch('coffee.jpg')
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  } else {
    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);
});
Tired Toucan

JS aguarda

const a = async () => {	
  	await b();
  	c();
};
Solstice

Respostas semelhantes a “JS aguarda”

Perguntas semelhantes a “JS aguarda”

Mais respostas relacionadas para “JS aguarda” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código