I am trying a little experiment here using Async without the Await. So what I did here is using Async with promise in the Fetch API. I am not getting the return in line 14 but line 8 works fine. Attached is the code. What should it have been? Thanks a lot and in advance.
async function getUserAsync(name)
{
let data
fetch(`https://api.github.com/users/${name}`)
.then(response => response.json())
.then(response => {
data = response
console.log(data) //line 8
})
return data
}
getUserAsync('john')
.then(data => console.log(data)) //line 14
fetchtodata? To answer your question: yes you can but you need to make sure your function returns a promise. Otherwise whatever it returns will be wrapped in one that immediately resolves. Sometimes it's not what you want; and certainly not in your specific case.