loading...
Cover image for Naming Conventions in 3 mins
DeSpider

Naming Conventions in 3 mins

sadiqur_rahman profile image Sadiqur Rahman Updated on ・2 min read

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_

Posted on by:

Discussion

markdown guide
 

According to wiki, Screaming case also known as Macro case