Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Variables Vs Constants - Part 3

Notes:

Naming conventions for JavaScript variables and constants:
Naming conventions are the rules for forming variable or constant names

1. Variable name and constant name should be meaningful
2. Keywords should never be used as variable name or constant name
3. The first character can be an alphabet, underscore or dollar character
4. The first character should not be a number
5. All succeeding characters can be alphabets, digits, or underscores
6. No special characters are allowed except an underscore or dollar
7. More than one successive underscores or dollars should not be used
8. Variable names and constant names are case sensitive
9. White space is not allowed
10. Use camel case naming convention for naming variables
i.e. if there is a single word in a variable name, then all characters should be in lower case letters, and if there are more than one words in a variable name, then first word’s all characters should be in lower case letters and all succeeding words first character should be in upper case letter, and all succeeding characters in all succeeding words should be in lowercase letters.
11. Whereas while naming a constant, all characters should be in upper case letters, if there are more than one word in a constant, then words should be separated by an underscore character.
12. No two variables or constants should have same name in the same scope
13. Always initialize a variable and constant, when they are declared
14. Always use var keyword for declaring variables
15. Always use const keyword for declaring constants

Interview Questions: