What are the point of classes in JavaScript?

I may be missing something really obvious here, but what actually are the point of classes in JavaScript?

I’ve never had a professional dev job (working on that), but have been coding for about ~4 years now - primarily in JavaScript. Not once in that time have I actually needed to use a class in any project I’ve worked on.

I understand the principle of using interfaces in TypeScript, and the fact you control common groups of information across your app - but in what circumstances would I actually use a class in a production application? It feels like if I want that level of control, I use TypeScript, otherwise I can just get away with writing functions and using objects.

Does anyone have any good examples of where classes are actually used in real JavaScript apps?

React was all class-based for a long time (and there’s still a lot of class-based React out in the wild). That’s just one example, but there are plenty of others.

The class syntax is basically just adding a more familiar OOP syntax to prototyping and inheritance that JS has always had. So are you asking specifically about why the newer class syntax was added? Or are you asking why JS has prototypical inheritance to begin with?

As for why the class syntax was added, I think it was because as JS began to grow and become more important to web development you had a ton of people migrating from OOP languages who were much more comfortable with the class syntax and so there was a ton of pressure to add it to JS. I will readily admit I am one of those people. C++ was my first programming language and I really appreciate the newer class syntax that was added to JS.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.