For being a good software engineer, it's too important to know what is the best practices for writing code and naming your variables, functions and classes properly, well this article will help you with it.
Case Styles
Basically, there are 4 ways of naming in general:
PascalCase
kebab-case
snake_case
camelCase
Now let's see each one of them in action for proper naming
Pascal/Studly Case
Also called Studly Case it basically means you write all words combined without any separators (not even whitespaces) and each word of the statement MUST be capitalized.
Let's say for example we've the following statement
total online users
To Be
TotalOnlineUsers
So what are our cases that we should write our code in studly case style?
It's recommended to use it in OOP classes, React Function Component, Typescript Types and Interfaces.
It's also called Underscore Case and it's basically writing all words combined with an underscore _ between each word.
It usually used in Python and Ruby and it's also used in SQL and MongoDB for naming collections but does not have pretty much usage in Nodejs or Javascript.
total online users
To Be
total_online_users
Camel Case
It's also called Camel Case and it's basically writing all words combined with the first word in lowercase and the rest of the words are capitalized.
It's recommended to be used in Javascript and Typescript for naming variables, functions and constants.
Crafting a simple JS tool for developers to convert text between cases (snake_case, camelCase, PascalCase, etc.). Save time and ensure consistency in your code with this our online case converter.
Thanks for a clear guide on the best practices for case styles in JavaScript and Node.js. Understanding when to use camelCase, PascalCase, snake_case, and kebab-case can significantly improve code readability and consistency. The examples for each case, like using PascalCase for classes and React components, kebab-case for HTML/CSS classes, and camelCase for variables and functions, provide practical insights into how these styles should be applied in real-world scenarios. This is important for maintaining clean, professional code in any JavaScript-based project.
For easy conversion between these case styles, check out our corresponding case converters:
I'm a professional Full stack Software Engineer who specifically is interested building projects' low-level structure.
I'm looking for a good oportunity for hiring, mail me if you find me fit.
Top comments (3)
Thanks for a clear guide on the best practices for case styles in JavaScript and Node.js. Understanding when to use camelCase, PascalCase, snake_case, and kebab-case can significantly improve code readability and consistency. The examples for each case, like using PascalCase for classes and React components, kebab-case for HTML/CSS classes, and camelCase for variables and functions, provide practical insights into how these styles should be applied in real-world scenarios. This is important for maintaining clean, professional code in any JavaScript-based project.
For easy conversion between these case styles, check out our corresponding case converters:
Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍
Thanks for your support :)
Really appreaciate it.