Sometimes, you have to wait for something to finish in JavaScript. Maybe you're waiting for an endpoint to return some kind of data. Well, how should JavaScript handle it? Stop all processes and wait for it? Well, no. So, an asynchronous (async) function can return a promise. It's promising you that it will finish whatever it's doing in some time. You can use await to wait for the promise to be fulfilled, in which case you need to use it inside an async function.
Sometimes, you have to wait for something to finish in JavaScript. Maybe you're waiting for an endpoint to return some kind of data. Well, how should JavaScript handle it? Stop all processes and wait for it? Well, no. So, an asynchronous (async) function can return a promise. It's promising you that it will finish whatever it's doing in some time. You can use
await
to wait for the promise to be fulfilled, in which case you need to use it inside anasync
function.a recently written article I just found
Thanks