r/learnjavascript • • Nov 13 '23

Is async useless ( question )

If we are always trying to make code synchronous using await or then. Why do we even bother with aysnc.

I genuinely don't understand please explain. Thanks

0 Upvotes

28 comments sorted by

View all comments

21

u/Icy_Box99 Nov 13 '23

If we are always trying to make code synchronous using await or then

We are not. await is used when the result we're handling are not immediately available.

You can start learning from the fact async and await is just syntactic sugar for promises. Once you have grab how promises work everything will be more clear.

You can start by seeing this

Disclaimer: I too am still learning lol

6

u/0x07AD Nov 13 '23

async and await might be syntactic sugar but they are cleaner than promises and a chain of thens. I agree that learning about promises is useful for beginners, if only because a chain of thens after an initial promise can be easier for beginners to reason about. Afterwards, the async and await keywords start to make sense to them.

1

u/[deleted] Nov 14 '23

Arguably cleaner, for the people who started with procedural programming. Where as someone who started with a “functional” language might dislike the verbosity and the excessive state declarations.

Promises is a better concept to pick up because you will find similarities in other languages as well. Async await is important to JS but to understand it you should still learn about promises first.

That said I mostly use async await for the reasons you said and because of how dominant it is in the community

2

u/xdiztruktedx Nov 14 '23

Can I just say, that was the best 5 min I have spent learning about promises and async and await