Here is my code
function save_current_side(current_side) {
var result;
var final = a.b({
callback: function (a) {
console.log(a); // its working fine here
return a;
}
});
}
where b is the synchronous function.
I am calling the above function anywhere in the code
var saved = save_current_side(current_side);
The variable saved is undefined. How to get returned valued by callback function
If
bis a synchronoys method, you simply store the value in a variable, so that you can return it from thesave_current_sidefunction instead of from the callback function:If
bis an asynchronous method, you can’t return the value from the function, as it doesn’t exist yet when you exit the function. Use a callback: