r/learnjavascript • • Mar 19 '26

What's the use of classes in JS

I've recently started learning JS and I can't see a use for classes. I get how they work and how to use them but I can't see an actual real use for them.

40 Upvotes

117 comments sorted by

View all comments

Show parent comment

1

u/kap89 Mar 19 '26

I see you edited your comment.

I thought closure technically means it has to maintain live references to something in the function’s scope after it returns?

What do you mean by "live reference" here?

1

u/prehensilemullet Mar 19 '26 edited Mar 19 '26

Basically if it needed to be able to read or write mutable variables on Hero’s scope after it returns.  In this case, even if the methods were declared as variables could be overwritten later instead of function declarations, it only has to read them once during method execution.