There are two ways to get an response from a function call:
Synchronous function
Everything after value = sincFunction();
will wait until sincFunction()
will execute and it will return a result.
function sincFunction() {
var value;
while(...) {
// do something
}
return value;
}
var value = sincFunction();
// Do something with item
doSomethingElse();
Asynchronous function
This is the opposite of the synchronous function, in this case there will not be any waiting on execution for the asincFunction function. Using a callback you can retrieve the response after the function is completed and you have the result.
asincFunction(function(value) {
// do something
});
doSomethingElse();
Result Box
- html
- css
- js