dvas0004 / NerdNotes

A collection of notes: things I'd like to remember while reading technical articles, technical questions I couldn't answer, and so on.
11 stars 0 forks source link

A note on JavaScript Async/Await #102

Open dvas0004 opened 4 years ago

dvas0004 commented 4 years ago

We can only await for an actual result from a promise within an async function, while the async function itself will always return a promise. For example:


const demo = async () => {
   const response = await Axios.get("http://example.com") 
   //"response" will contain the actual JS object
}

const p = demo() 
// "p" will contain a pending promise, NOT the actual data