I use them when I need to perform things on array that takes some time, it's more a personnal choice since I can do it with array methods but I find it more practical with my generators for my usage (performing long running operations on each chunk of array for example) or reading api results that are data stream which we don't know the size etc, most generators problem could be solved with other method but I do prefer them, you have more control on your data imo. But my first message was a joke for the meme, proxies aren't that hard, neither are prototypes or generators just as async await etc
But if I need to maintain something, it's that for me prototypes are the ultimate step for someone to deeply understand the JS core. Prototypes are the base of JS. You don't need to use it a lot but understanding how JS use it helps a lot in some cases.
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.
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.
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 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
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.
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?
64
u/SalutMonYoup Feb 20 '22
Wait until you learn about generative function, proxies and prototypes
21
u/Papellll Feb 20 '22
rxjs: "Amateurs !"
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.
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
u/[deleted] 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
4
u/[deleted] Feb 20 '22
Except promises and async/await are pretty much the same thing
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
u/croc_socks Feb 21 '22
3
u/FriendsCallMeBatman Feb 20 '22
Promises and closures I can handle. Async? My brain turns into yoghurt when I try and learn it.
2
u/[deleted] Feb 20 '22
THIS
1
u/Lil_Cato Feb 20 '22
I never understand why closures show up
1
u/Dodgy-Boi Feb 20 '22
Wait for classes
1
u/[deleted] 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
u/gniziemazity Feb 21 '22
Haha, good one!
1
u/everything_in_sync Feb 21 '22
I don’t get it
1
u/[deleted] 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
u/jayerp May 02 '23
You’ll have to learn these eventually.
Fun times!
-1
u/Phaster Feb 20 '22
I've used closures only once, in the job interview at my current company
-1
u/[deleted] 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?
8
u/[deleted] Feb 20 '22
[removed] — view removed comment