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)
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
According to wiki, Screaming case also known as Macro case