This is why closures are important in javascript #shorts

preview_player
Показать описание
You often need to use a closure to create private state that only a function knows about. Here is an example of when you can use a closure.

------------

Рекомендации по теме
Комментарии
Автор

Those who code in React would understand better. There are class components when we use oop and there are function components that use functional programming. In function components, when we declare variable inside a component or create states using useState(), we are essentially taking advantage of the concept of closure. Every time i call the function component somewhere, each one would be a seperate instance of that component. And no oop used for this to happen.

lazyadult
Автор

Well this is why we have something called class 🙂

ahmedb.hameed
Автор

Nice break down! Your shorts are so well spoken and concise too

mimoduocss
Автор

After watching tutorial video reading the documentation this simple and crisp video is much needed!!!
Thank you sir!

jesmeeksinghmusic
Автор

Omg!! Thnk u so much I've been struggling to understand closures really this just made it clear it all.

avelon
Автор

Okay, as a person not familiar with js, the only question I had the entire time is: "What, the actual fuck?"

NuclearJeday
Автор

Javascript has so specific issues and so specific solutions for those issues its *almost* beautiful

katalysmus
Автор

Thanks for explaining closures in less than a minute

sourabhkulkarni
Автор

Do more on async promise and call backs

telugucodingguy
Автор

Thank you for this video! Really intuitive explanation, subscribed!

mitkomilev
Автор

I'm just getting started with React, and have actually been using this without realising 😅..

wanainai
Автор

You are the man bro, You explained this in a very simple way...HUGE RESPECT 🥰🥰🥰

abdulazeez
Автор

The important thing to understand is not “closures are THE way”, but “closures are A way”, and this little example is an easy way to play with them.

To understand what is happening in JS you must understand how it’s closures and objects work, among many other things. Ignoring one (or worse, framing understanding of JS objects in terms of more typical OO languages like Java) will leave you confused when you inevitably run into code using that other thing. Code in a way your brain understands, but be able to read and understand as much as possible.

atalhlla
Автор

I just learned what classes are and how they work and this thing looks like a class... are classes something newer or older than closures?

danser_theplayer
Автор

Thank you! I was looking for this the other day! 👏👏

vsowill
Автор

What extension let’s you auto comment the console log? That’s awesome

parenthecoltsenr
Автор

This is one of the best explanations about closures I have seen. Simple and to the point. Most of the time people will lose themselves with technicality.

pcostarg
Автор

What I most like of this channel is that it goes direct to the point.

rodbrowning
Автор

How do we get the value of the count in this case? Do we return an array of 2 functions one for setting count and other for fetching it or is there another way to do that?

piyush
Автор

I didn't understand what's the problem in the example counter program was just working fine...why we can't have that as external variables

lalit-singh-bisht