1. JavaScript
  2. Introduction
  3. Naming Conventions

JavaScript Naming Conventions

Last updated:

Consistency is key.

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

  • consistency is key.
  • descriptive names are better than short names.
  • camelCase for variables and functions.
  • PascalCase for classes.
  • UPPERCASE for constants.
  • Avoid using reserved words and special characters in names.