last day (15 days later) » 

09:38
1
A: How to return values from async functions using async await from function?

Pac0your function getData will return a Promise. So you can : await the function as well to get the result. var x = await getData(); console.log(x); or use the result as a normal Promise, which is what an async function returns : you have to use then with a callback : getData(...

Hello @pac0, I got this error prntscr.com/j7qqeu
can't follow this kind of link from where I am. Please copy the message as text.
It's telling me , I did a syntax error "C:\Users\kingr\Desktop\test\index.js:9 console.log(await getData());"
Then, use the second option, this one should not cause trouble.
I think , you can follow this link to see screenshot i.stack.imgur.com/3nxej.png
09:38
(yes, I can with this one, thank you)
I knew about that second option, but I'm looking for a way to get all api data in a variable or function instead of using then by promise. I can get them inside a async function with await but I can't return them for using that data outside. Isn't it possible? I think I could make my query clear to you,, thanks @pac0
Hello @pac0
Hi
I edited my asnwer to fix the way await should be used.
Thanks for your effort to helping me out
no problem
let me know if this works.
can you hold for me for some moments plz? if you have some time please
09:41
not too much, but I can check some time to times.
(sorry for English errors, not my language)
Just concerning your question, an async function will always return a Promise, that's how it works.
I'm getting syntax error
Yes, I see, that's because you can only use await in an async function.
so unfortunately, on the "top level" (without being in a function), you cannot use await.
Can you wrap your code in an async function ?
like
async function testCall() {
var x = await getData();
console.log(x);
}

testCall();
now testCall() is actually a Promise, but you don't need to get a return value from this wrapping function, so it should work.
I got it
Thanks you so much
Thanks for your valueable time
good bye @pac0
you're welcome, thank you too

last day (15 days later) »