Before we get started, here is what you need to know first.
There are different case styles used across different programming languages to name the variables. Let us discuss some of the case styles.
Camel Case: It is the practice of writing phrases without spaces or punctuation, indicating the separation of words with a single capitalized letter, and the first word starting with lower case.
Pascal Case: It is very similar to the camel case, but the first letter starts with Upper case.
Snake Case: Here we separate the words using underscore (
_) and the words can be either in lower or upper case. Example:
Dynamic Variables: whose value keeps on changing.
letis used to define the dynamic variables with primitive values (such as strings, boolean and numbers, etc.). And we also use
constto define the dynamic variables with non-primitive values (such as objects and arrays). It is preferred to use Lower Camel Case for naming the dynamic variables.
Constant Variables: whose value remains constant and doesn’t change.
constis used to define the constant variables. It is preferred to use Upper Case for naming the constant variables.
- If the constant variables name has more than one word, then it is recommended to define it using the Upper Snake Case style.
The function names are also preferred to be defined using the Lower Camel Case style.
The class names are preferred to be defined using the Pascal Case style.
React components (both class and functional components) are usually named in the Pascal case.
It is preferred to use Lower Camel Case for naming the exported node module names.
- Variable names should start with either a letter, underscore (
_), or a dollar sign (
- Variable names cannot start with numbers or any special character other than underscore or dollar sign.
- Variable names can have numbers, but not at the beginning of the name (first letter).
- Variable names cannot have spaces.
- Use meaningful names like
ShoppingListand avoid ambiguous names/abbreviations.
- Names should specify what value it is holding (like
employeeName) in case of variables.
- Names should specify what action it is doing (like
updateCartItems) in case of functions.
Let us summarize the items we have learned so far.
Thank you for stopping by. If you like the content do support me and follow me for more content like this.