support@90-10.dev

JavaScript Naming Conventions

JavaScript naming conventions are a set of rules to follow while naming variables, functions, classes, and other identifiers in your code. They are designed to help write clean, organized, and easily maintainable code by following these rules agreed beforehand either across a business or a team.

The most important benefit is consistency - it does not matter much what the conventions are - what matters is they are applied in a consistent and holistic way.

Here are some common naming conventions that developers use in JavaScript - use this as a starting point and make a list of your own:

Variables

  • Variables should always start with a lowercase letter: name.
  • If the variable name is made up of multiple words, use camelCase: firstName instead of first_name.
  • Do not use reserved words and special characters in variable names.

Constants

  • Constants should be in all uppercase letters: PI.
  • If the constant name is made up of multiple words, use underscores: MAX_SIZE instead of maxSize.

Functions

  • Function names should always start with a lowercase letter: calculate.
  • If the function name is made up of multiple words, use camelCase: calculateTotal instead of calculate_total.
  • Function names should be descriptive and indicate what the function does.

Classes

  • Class names should always start with an uppercase letter: Person.
  • If the class name is made up of multiple words, use PascalCase:  PersonDetails instead of person_details.

Take Away

By following these naming conventions, you can ensure that code is easy to read, understand, and maintain, making it easier to debug, update and collaborate with other developers on a project.

Keep in mind that having naming conventions does nothing unless they are followed and enforced.