The answer to your question is no.
In asynchronous requests, the function must return before the result is received. To get around this, a callback template is used - when you call such a function, you do not expect a return, but rather provide it with a callback - a function that will be called when the result is available.
Here is a simple example:
var someValue; fetchValueFrom('http://example.com/some/url/with/value', function(val) { someValue = val; doSomethingElseWith(someValue); });
Here we create a function and pass it as the second parameter to call fetchValueFrom . Once the value is available, this function will be called and will set a variable and call another function to continue execution.
source share