Callbacks vs Promises vs Async/Await

So, as for now, I’ve only been using callbacks to manage asynchronicity on express. I understand that async/await is just another syntax to promises. So, I have a few questions

  • Can I use any of them while working on express i.e?
  • Is there any functionality in any of them missing from the others?
  • Is it any of them preferred to the others? Why?
  • Can or should I use a mix of them in my code?
  • Is there any advantage in different situations to any of them?
  • Why are freecodecamp lesson written using callbacks, whereas mongoose documentation, for instance, is written mainly using Async/Await?
  • Is freecodecamp outdated?

Thanks!!!

I do believe the heavy use of callbacks to be a sign of the aging curriculum. I don’t think I would ever really prefer callbacks. Using callbacks tend to get messy really fast especially with multiple callbacks (callback pyramid of doom).

As for when and how to use promise/async/await I would suggest you take a look at some newer articles and tutorials to see how more modern backend code might be written. It can really help clean up the code.

1 Like

Not the pyramid of doooooooom :scream:

I agree. I vastly prefer async/await to callbacks - as lasjorg mentioned it’s very helpful for clean and maintainable code. Additionally, using await allows you to store the return value of a promise/function in a top-level variable which can be passed around wherever, whereas callbacks scope the return value to within the callback function.

You can - I use async/await with my express apps without issue.

I would definitely recommend against this. I would choose one or the other for a project, or you’ll end up creating additional confusion for yourself.

There are certainly aspects of the curriculum that aren’t up to date. The challenge with technology is that it is ever evolving, which means maintaining information on the latest and greatest is a lot of overhead.

We are, however, working on some significant revamps to our curriculum, which you can read about here:

Project-based Curriculum
Data Science Curriculum

1 Like