Synchronous vs. Asynchronous

Synchronous = executed after each other, so line by line. NOT the classic definition of synchronous.

Asynch = while doing X, JS can do Y in the background. Therefore what we would call “synchronous” in the classic definition, don’t be confused.

Promise.then(function() ...)
	.then()
	.then()
	
// Would be executed already, once the Promise execution started 
// even though the promise might not have finished now. 

Await meanwhile blocks the execution, even for other statements which are on the same level than the await-line.

const getData = async (db) => {
  const res = await db.query('SELECT * FROM users')
  
  // won't happen before: 
  return res.rows
}

This print-statement “hello world” might very well be executed before:

const getBenutzer = (db) => {
  return db.query('SELECT * FROM benutzer')
    .then((res) => {
      console.log(res.rows);
    })
    .catch((error) => {
    });
  console.log("hello world");
};