Answer the question
In order to leave comments, you need to log in
How can I return the result of a callback function in a function?
What needs to be done so that the do function returns the result of the getUrl function?
function do () {
getUrl(function () {
let a = 5;
return a;
}
}
console.log(do()); //5
Answer the question
In order to leave comments, you need to log in
Learn Promises
function do() {
return new Promise((res, rej) => {
getUrl(() => {
const a = 5;
res(a);
})
})
}
do().then(res => console.log(res));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question