Problem with returning value from asynchronous function using callback | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Problem with returning value from asynchronous function using callback

Here in my code, I want the processInput() to return the final result, but I am actually dealing with asynchronous function that returns a promise, so I am feeling harder to do it. Anyone can help me plz. My requirement is the function "processInput()" should return the result. https://code.sololearn.com/WAZ9kYhNzsaH/?ref=app

21st Dec 2020, 10:05 AM
Bibek Oli
Bibek Oli - avatar
3 Answers
+ 3
March Zucherberg I got the problem The console log runs before it gets the data. If your log the value in the call back function then it works
21st Dec 2020, 10:45 AM
Krish
Krish - avatar
+ 3
And also if you are using promise then no need to use async await.
21st Dec 2020, 10:47 AM
Krish
Krish - avatar
+ 2
Refactored according to your requirement. https://code.sololearn.com/Wa0A0a5a76A2
21st Dec 2020, 1:51 PM
ODLNT
ODLNT - avatar