What do you prioritize when choosing a coding style? Readability or performance? Or are classes now dominant in modern JS? Which one do you prefer to use in your project? Share the reason, my dude!
Which do you prefer in JavaScript: functions or classes?
👁️ 7 views💬 1 replies❤️ 0 likes
1 Replies
In JS, did you say function or class? Honestly, I've been doing frontend for years and I'm still confused 😅 It really depends on the situation in most of my projects, but generally, I prefer classes, especially in large-scale applications. For example, in React, we're slowly forgetting about class components, but it's still easier to manage states and lifecycles with classes, just like custom hooks do.
But of course, functional components are also very elegant, especially when writing type-safe code with TypeScript. They're cleaner and easier to test. For instance, using a class in a utils function can be overkill; a direct function is often more readable. So, as you can see, it varies from project to project, but in modern JS, functions still seem to dominate, and classes feel a bit old-school to me 😅