How do closures work? (JavaScript Fundamentals, 2023)

preview_player
Показать описание
Closure is a fundamental feature of JavaScript, arguably one of the features that made it as widely usable as it is today. In this video, we'll take a look at how closures work and what you can do with them.

*My Links*

#coding #javascript #closure #ecmascript
Рекомендации по теме
Комментарии
Автор

This is probably the best content on this topic I've seen in a long time. Well done Andrew and thank you for the great content. Keep it up!

JosimarBezerra-fxwb
Автор

First time this concept really made sense to me. Thank you.

lifeofmrc
Автор

Really informative. More on fundamentals please.

emreozgun
Автор

I've learned that closures in JavaScript help you to avoid syntactic classes.

And now, for first time, I have somehow gotten my head around it

thedelanyo
Автор

Man I love your theme so much. This was a good video, I'll probably never use it, but it's good to know it's there. Thanks!

CodeOnBlocks
Автор

Love your VS Code settings.. Please share with us!

moreshwardalavi
Автор

Can you share your .nvim dots?
It looks awesome.
Also, is that Catppuccin theme?

milutinke
Автор

Next Video! Prototypes and Production level usage

yt.neerajkumar
Автор

Thx for this video)
Maybe next video about closures in React?

artyomtaranenko
Автор

Hey, thanks for the video.

What's the extension you use to get error messages show up in the IDE so nicely?

(E.g. private not available in JS)

ibraheem
Автор

Markiplier's younger brother, is that you?

flippa_da_boss
Автор

Here is what I don't understand:
let foo = 1;
function test() {
console.log(foo);
}
if (true) {
console.log(foo);
}

The fact that the *function* can access the outside variable is because of "closure". Right?
The fact that the *block* can access the variable is _not_ called closure, though. It doesn't have a fancy name. But it's actually the same idea, isn't it???
Why are there tons and tons of videos like this, trying to explain something (that just makes JavaScript work as one would expect), BUT ONLY when it's about functions -- and there is apparently no need for explaining anything when it's about blocks??

I mean, I don't think we need this stupid word in the first place... but why isn't it used for blocks? Or is there a difference that I missed?

dasten
Автор

"You might think this pattern is out of date" - absolutely not! Putting classes into JS was massively wrong-headed. JavaScript is LISP dressed up as C and trying to turn it into "Fake Java" with classes is just "disgusting". In a class, you can label something as `private` but with closures it really, actually is private. Closures are bad for inheritance, but what the hell would you be trying to do with inheritance in this day and age anyway... I think of the meme of Bart Simpson stood at the blackboard, writing out 100 times "I must learn to prefer composition over inheritance". ;)
I just don't understand why people would want to take a perfectly good functional language and try to turn it into the same old mistaken vision of OOP that C++ gave us years ago.

edgeeffect