As we discussed previously, variables are instrumental in any programming language and without variables, I would have to change the value everywhere manually. But with variables everywhere we reference the variable, it will automatically get adjusted to the new and updated value. For a detailed introduction of variables, you can go through this post.
If you are following along the course in the sequence, you might have come across me naming a variable
firstName. This way of naming is called
camelCase. camelCase means that whenever I have multiple words in a variable name, I write the first word starting with the lower case, and then all the following words will also start with capitals.
Rules of naming a Variable
- We cannot use integers as variables.
- We cannot start a variable with an integer.
- Variable names can only contain letters, numbers, underscores, or the dollar sign.
functionas a variable
- Even though
nameis a reserved js variable, we can still use it.
Other Conventions, but to be considered as Rules
- We should not start a variable with an uppercase letter
- Variables that are all in Uppercase are reserved for constants that we know will never change
- Make sure that the variable names are descriptive
These rules and conventions are fundamental to write cleaner code. Any developers code should be straightforward to understand. With these rules and patterns, we can understand what value the variable is holding by reading the variable's name.