Question: I have this simple code:

```
(async ()=>{
    const five = await printHello()
    console.log(`five: ${five}`);
})()

async function printHello(){
    console.log('Hello World')
    return 5;
}

console.log("App started");

```

My expectation is that it should print :

```
App started    
Hello World
five: 5

```

As the anonymous function that gets executed is marked async.

However it prints, even after multiple trials :

```
Hello World
App started
five: 5

```

Can some one please explain me why this is happening ?

Answer: 
First, you call `printHello()`.

Then you call `console.log('Hello World')` which logs.

Then `return 5;` which resolves the promise.

Then you `const five = await ...` which awaits the promise returned above. This is a microtask so it gets queued up and the async function goes to sleep.

The IIFE finishes running, so the outer function continues with `console.log("App started");` which logs App started.

Then the outer function finishes, so the microtask is pulled off the queue and the async function wakes up.

The resolved value from the promise is assigned and `console.log(`five: ${five}`);` logs it.

See [Timing from MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#Timing) for further reading.
Your code is not asynchronous. That is this the problem. You need to return a promise that is always asynchronous. 

```
const users = [
  {
    id: 0,
    name: 'foo',
  },
  {
    id: 1,
    name: 'bar',
  }
];

function getUserById(id) {
  return new Promise((resolve, reject) => {
    setTimeout(function() {
      resolve(users.filter(user => user.id === id)[0]);
    }, 1000);
  });
}

async function getUser(id) {
  let name;

  await getUserById(id).then(function(user) {
    name = user ? user.name : null;
  });

  console.log(name);
}

getUser(0);
console.log('console');

```