CodeNewbie Community 🌱

Kate
Kate

Posted on

How do I return the response from an asynchronous call?

Hello from the north!

I've been enjoying learning JavaScript and have made it through most of my course. But, I've gotten a little stuck on the issues of returning responses from asyc calls.

Can anyone help me figure this out?

Thanks!

Top comments (1)

Collapse
 
ender_minyard profile image
ender minyard

Writing synchronous code, you can retrieve the response of a synchronous call as such:

let response = function1();
Enter fullscreen mode Exit fullscreen mode

If function1 is a Promise, one could rephrase the above as

(async () => { 
let response = await function1();
})();
Enter fullscreen mode Exit fullscreen mode