I’ve been reading nodebeginner
And I came across the following two pieces of code.
The first one:
var result = database.query("SELECT * FROM hugetable");
console.log("Hello World");
The second one:
database.query("SELECT * FROM hugetable", function(rows) {
var result = rows;
});
console.log("Hello World");
I get what they’re supposed to do, they query the database to retrieve the answer to the query. And then console.log('Hello world')
.
The first one is supposedly synchronous code.
And the second one is asynchronous code.
The difference between the two pieces is very vague to me. What would the output be?
Googling on asynchronous programming didn’t help me either.