21
31
u/rubenthedev Feb 20 '22
I gotta disagree here, if you're worrying about closures you really don't need to be considering any async handling. If you're struggling to understand async functions and what await is used for within them, your understanding of asynchronously executing code needs work. If you don't understand promises, you'll need to understand what synchronous code is, then how the JS event loop works, and why one might want to step outside of it.
Basically, of the three, closures are a requirement for understanding how JavaScript works beyond the absolute basics, and it shouldn't be too difficult if you've got that base level of understanding. The reason behind that is this, once you've written enough JS the way it interacts with itself starts becoming clearer, to the point that most JS devs I know understand the concept of closures before learning that there's even a name for it. The exception being the ones that started in language and thus had to learn the difference in function scope handling. It basically, like anything else you want to get good at, comes down to practice. Repetition and refinement, so you can carve out those neural pathways.
The other two are JS's implantation of general concepts in programming, and to attribute them to difficulties in learning JS speaks to a lack of understanding of the general concepts and not to a JS gotcha. Which to be fair, there are many of, these just aren't in that collection.
8
u/danglesReet Feb 20 '22
This. None of the aforementioned concepts are that hard.
34
6
u/IronDicideth Feb 20 '22
Promises are amazing. Once you get promises, at least in my case, I never really find myself needing to use async/await (though I understand why it is easier for others). Top-level await can be really useful though. Closures was never really a super hard concept. I think the issue with them is how people insist on using old var centric examples to explain how it works. There is a guy that is really good at explaining closures. I believe his name is Will Sentance. He probably has videos somewhere on the internet explaining the thing.
4
Feb 20 '22
From over a month I can't fully understand Promises and async await. :(
Whenever there is code for this my brain goes on sleep mode
3
u/bpippal Feb 21 '22
Yeah, don't give up. Learn a little every day.
https://www.youtube.com/watch?v=V_Kr9OSfDeU - Async/Await
https://www.youtube.com/watch?v=DHvZLI7Db8E - Promises1
2
4
7
u/sparkless12 Feb 20 '22
frankly, before I encountered promises, I considered myself relatively intelligent human being, then everything changed.
7
u/AlarmingAffect0 Feb 20 '22
You thought you could use integers, but...
We're all floats down here, Georgie.
3
3
u/FriendsCallMeBatman Feb 20 '22
Promises and closures I can handle. Async? My brain turns into yoghurt when I try and learn it.
12
Feb 20 '22
Async/await is syntactic sugar for promises, it appeared to make it easier dealing with promises
3
1
u/bpippal Feb 21 '22
Yeah, what ever you think you can achieve using Promises/.then, you can get them using async await.
2
Feb 20 '22
THIS
1
1
u/Anti-ThisBot-IB Feb 20 '22
Hey there rapuha! If you agree with someone else's comment, please leave an upvote instead of commenting "THIS"! By upvoting instead, the original comment will be pushed to the top and be more visible to others, which is even better! Thanks! :)
I am a bot! Visit r/InfinityBots to send your feedback! More info: Reddiquette
1
1
1
Feb 20 '22
I finally understood promises with Axios and websockets. Async/Await I understood with websockets and event notification messages. Closures I could still use some time with
1
u/croc_socks Feb 21 '22 edited Feb 21 '22
JavaScripts module system ( commonjs vs esmodules )for bringing in dependencies in node.
1
1
u/everything_in_sync Feb 21 '22
I don’t get it
1
Feb 21 '22
Neither does the guy walking in the door. That's why he's in for a world of pain.
1
u/everything_in_sync Mar 03 '22
No, I don’t get it because their functions are literally in their titles and I don’t understand how that could sneak up on you
1
Feb 21 '22
I just started learning as a lapsed developer of 25 years (haven't coded much since uni) and as soon as I started to find out about the asynchronous nature of JS my heart just sank.
I'm about to start tackling these concepts when I have enough brain space so wish me luck.
1
u/reyzapper Feb 21 '22
Promises and async/await are easy.
but I never get a grasp with Closures, can someone explain it the easy way??
1
-1
u/Phaster Feb 20 '22
I've used closures only once, in the job interview at my current company
0
Feb 20 '22
[deleted]
1
u/Phaster Feb 20 '22
Most packages/libraries use them yeah, but intentionally creating a closure, for me at least, only happened once
6
-1
Feb 20 '22
Modern JS barely does use closures, you still have to know about the concept, sure. As for Promises and async/await those make your code MUCH more readable so what is the problem?
4
8
64
u/SalutMonYoup Feb 20 '22
Wait until you learn about generative function, proxies and prototypes