DEV Community

Cover image for Naming Conventions in 3 mins
Sadiqur Rahman for DeSpider

Posted on • Updated on

Naming Conventions in 3 mins

Naming Convention
There are so many different ways you can name your variables (naming conventions). If you are a beginner, most probably you don't care a lot about naming. But if you are working / planning to work in a team, lets learn a bit of naming conventions before you embarrass yourself. 😉
Here are some common conventions;

🐫 Camel Case: First word of the variable has to start with a small letter, then the second or third word will start with capital letter. Examples: newVariable, iLikeCamelCase. Used for assigning string, number, boolean, object, array, list and so on.

👵🏽 Pascal Case: It is like camel case, except for the fact that it starts with a capital letter. Examples: NewVariable, ILikeItToo. Mainly used for declaring a class and it's types (Object Constructor Function, Interface…).

🐍 Snake Case: Here we have small letters with underscore (_) separation, like this_one. They are very handy for object keys and for database fields. This could also be used to declare a really_really_loooong_variable.

🍖 Kebab Case: In this type, small letters are grilled together using hyphens, just-like-this-example. You can use it for routes (url) for instance, if you wish.

😠 Screaming Case: All capital letters, to YELL at people. If you want to hard code a value like TAX=10%, you can use SCREAMING_CASE.

⁉️ Hungarian Notation: In this type, names start with a lowercase prefix to indicate the intention. Example would be sName, nAge. Since in JavaScript, we don't have typing (string, number…), we can use hungarian notation to give a hint about the variable's type (s for string, n for number…).

_Underscore before a variable: This is a very common practice to declare a _privateVariable that cannot be accessed outside of a class.

To sum up, it is always a good practice to apply the "good practices" in your code. This makes your code more understandable, maintainable and most importantly makes you feel cool 😎

I wish you a safe, healthy and happy coding! 👋

Twitter: @Sadiqur_Rahman_

Top comments (2)

Collapse
 
stepanstulov profile image
Stepan Stulov

Really nice overview on capitalization conventions, but naming conventions is a different topic (so title of your post is misleading). I also suggest adding all-smalls case. Screaming case is sometimes called all-caps. Cheers

Collapse
 
vincentjonathan profile image
Owl

According to wiki, Screaming case also known as Macro case