synchronous vs asynchronous typescript code example

Example 1: difference between synchronous and asynchronous functions

stackoverflow

Example 2: synchronous vs asynchronous functions javascript

// Example 1 - Synchronous (blocks)
var result = database.query("SELECT * FROM hugetable");
console.log("Query finished");
console.log("Next line");


// Example 2 - Asynchronous (doesn't block) 
database.query("SELECT * FROM hugetable", function(result) {
    console.log("Query finished");
});
console.log("Next line");

Tags:

Misc Example