6 Reasons Why JavaScript’s Async/Await Blows Promises Away (Tutorial)
Mostafa Gaafar
3.9K59

Still missing something about `async/await` I think… In all your examples you are doing things like console.log(myvalue) inside your async functions. But what if you didn’t want to do console.log? What is you wanted to return the value instead? Because if you tried that, it would return a Promise, not the value you had within the async function. And furthermore, since the function is returning a Promise, what is the point of async/await since you can already simply return a Promise from a function anyways?

Let’s say I wanted a function that did the following:

  1. Check if a certain local file path exists using fs.exists
  2. use fs.readFile to read in the content of that file
  3. Return that content of the file

How would I do this using async/await? Can you (or anyone else) write out this solution? This is obviously very easy to do with just Promises, but the function would return a Promise.resolve() instead of the content of the file. What value does using async/await add to this? It seems pointless if the function still returns a Promise.resolve().

Show your support

Clapping shows how much you appreciated Jake Wilson’s story.