DEV Community

Discussion on: Async Await: 60% of the time, it works every time

Collapse
 
cwspear profile image
Cameron Spear • Edited

One of the biggest boons for async/await over .then is working with if statements and such:

async someFn(param) {
  const data = await getData();

  if (param) {
    data.other = await getOtherData(data);
  }

  return data;
}

That's much nicer than the alternative, which I'm not gonna type out cuz it was hard enough doing that much from my phone. But it is.

Especially if the first functions wasn't async and you had only a conditional async fn.

This isn't the greatest example, but there is a lot of stuff like this that gets much less messy with async/await. Especially if you are adding it after the fact, etc.

Collapse
 
ryan-haskell profile image
Ryan Haskell

Haha, that makes sense! And weirdly enough, I started this post on my phone and quickly switched over to my laptop. 😂