The Joy of Using Async/Await

Michele Riva
openmind
Published in
6 min readMar 11, 2019

--

JavaScript is an event driven language. This means that JS will keep executing code while listening to other events.
Ok, I know, this may not sound so clear, so take an example:

As you can see, JavaScript executes the functions above in order. But are you sure that it will wait until function one has terminated, before executing function two?

Wow! Other languages such as PHP, Ruby and Python would have waited until function one had finished before executing the next function, but JavaScript did not.
So, what if you need to make sure that function two will be called in the right order, after the function one?

Callbacks to the rescue!

Now take a look at the function above: we added an argument called callback which is a function that will be executed…

--

--