Asynchronous vs synchronous execution, what is the main difference?
Asynchronous:
In Asynchronous, will not wait to finish first task or response,
it will jump to another my by before finish, once the task get finish
simply it will report.
Asynchronous handle more then one task one at a time (Asynchronous work with 2 hands at a time).
Ajax is best example here.
Synchronous:
In Synchronous, will not take task until finish first.
"No, I'm waiting right here until you finish." This is synchronous.
Synchronous handle task one at a time (Synchronous work with 1 hand at a time).
==========================
// Example 1 - Synchronous will blocks the task
var result = database.query("SELECT * FROM employee");
console.log("Query finished");
console.log("Next line");
// Example 2 - Asynchronous doesn't block the task
database.query("SELECT * FROM employee", function(result) {
console.log("Query finished");
});
console.log("Next line");