Answer the question
In order to leave comments, you need to log in
How exactly does await get the result of a promise?
Hello. There is the following code:
(async () => {
const response = await fetch('https://jsonplaceholder.typicode.com/users');
console.log(response); // экземпляр объекта Response
})();
Answer the question
In order to leave comments, you need to log in
Maybe it will become clearer if we add a little from the classic example:
function fetch(addr) {
return new Promise((resolveFunction) => {
setTimeout(() => {
resolveFunction('addr response') // вызываем функцию, которая прилетела параметром
}, 3000)
})
}
(async () => {
const response = await fetch('https://jsonplaceholder.typicode.com/users');
console.log(response); // результат, который передали в resolveFunction
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question