What would be your order of learning Promise, async and await for beginner?

I’m at the lesson for writing promise, but there’s not much background covered in the lesson.

So when I look around, the basic seems to be.

  1. Synchronous vs Asynchronous.
  2. Callback function
  3. Promise
  4. Promise Chain
  5. Async/Await

Is this an appropriate learning order?

I think it is a good order. I would add Observables as number 6.

ok observables then…cause I heard alot of people have a hard time learning promise, so I want to make sure I get my basic down first in order before confusing myself.

That seems reasonable. The whole point to all of these things is to allow you to write code that does {thing that takes some unknown amount of time} without having to stop your program and wait for it to complete.

It is important is to understand the mechanism, I would watch this:

Callbacks are kinda the easiest to understand conceptually, but the logic can get convoluted – you want to do thing x, then once that’s done do thing y, then once that’s done do thing z. And so you have a function x that takes function y that takes function z that returns the final value based on the result.

Promises are a way to flatten that process out. You make your functions return an object called a Promise that may contain the return value. Then you can chain the functions instead of using callbacks: run function x, then function y, then function z. It’s still the same basic process, it’s just [in many situations] much easier to write and understand.

That still gets a bit convoluted, so async/await simplifies this further. Instead of explicitly wrapping things in Promises, you tell JS that a function is async so it’ll automatically wrap it in a promise, and then use the keyword await to tell JS to automatically try to resolve those promises to values.

All a bit abstract until you start to play around with it

More supporting learning material that might help: learnjavascript.online

Observables aren’t particularly important here. Kinda useful to know but not that widely used outside of specific cases, and they aren’t implemented as part of JS, only available via libraries. They can be used as a different way again to implement async logic (as can iterators/generators, which are part of JS. As can coroutines, which aren’t but can be implemented with generators).

2 Likes

Oh thankyou so much, I’ll go study each particularly the link.

1 Like

You should not be to concerned when people say it is hard to learn. In fact, I believe that with the right material you can learn Promises pretty quickly.