Last modified: Jul 22, 2026

JS Variable Naming Case Styles

When you write JavaScript, naming variables is a daily task. The way you name them matters a lot. Good names make code easy to read. Bad names cause confusion. This guide covers the main case styles: camelCase, snake_case, and PascalCase. You will learn when and why to use each one.

Why Case Styles Matter

JavaScript is flexible. It does not force you to use a specific case style. However, the community has standards. Following these standards helps other developers understand your code. It also helps you when you revisit old projects.

Consistent naming reduces bugs. It makes your code look professional. It also improves collaboration. Teams that follow a style guide work faster and make fewer mistakes.

The Three Main Case Styles

camelCase

camelCase is the most popular style in JavaScript. The first word is lowercase. Every following word starts with a capital letter. It looks like a camel's humps.

// camelCase examples
let firstName = "John";
let lastName = "Doe";
let totalPrice = 99.99;
let isActive = true;
let fetchUserData = function() {
  // function body
};

Use camelCase for variables, functions, and methods. It is the standard in JavaScript. Most frameworks and libraries use it. For example, getElementById and addEventListener both use camelCase.

If you are new to JavaScript, start with camelCase. It is the safest choice. It aligns with the official JavaScript style guide.

snake_case

snake_case uses underscores between words. All letters are usually lowercase. It is common in Python and Ruby. In JavaScript, it is less common but still valid.

// snake_case examples
let first_name = "Jane";
let last_name = "Smith";
let total_price = 49.50;
let is_active = false;
let fetch_user_data = function() {
  // function body
};

Some JavaScript projects use snake_case for constants or configuration objects. It can also be useful when dealing with databases. Many databases use snake_case for column names.

However, avoid mixing styles. If your team uses camelCase for variables, stick with it. Mixing styles creates confusion.

PascalCase

PascalCase is like camelCase but the first word is also capitalized. It is also called UpperCamelCase. It is used for class names and constructor functions.

// PascalCase examples
class UserAccount {
  constructor(name, email) {
    this.name = name;
    this.email = email;
  }
}

function Person(name, age) {
  this.name = name;
  this.age = age;
}

let myAccount = new UserAccount("Alice", "[email protected]");
let myPerson = new Person("Bob", 30);

Always use PascalCase for classes and constructors. It is a universal convention. It helps you instantly recognize that a function is meant to be used with the new keyword.

Best Practices for Naming

Here are some simple rules to follow:

  • Use camelCase for all variables and functions.
  • Use PascalCase for classes and constructors.
  • Use snake_case only for constants or when working with external APIs.
  • Be descriptive. Avoid single-letter names except in loops.
  • Keep names short but meaningful.

For more details on naming rules, read the JavaScript Variable Naming Rules guide. It covers what characters are allowed and what to avoid.

Common Mistakes to Avoid

Beginners often make these mistakes:

  1. Mixing styles in one project. Choose one style and stick with it.
  2. Using reserved keywords. Words like class, let, and const cannot be variable names.
  3. Starting with a number. Variable names must start with a letter, underscore, or dollar sign.
  4. Using hyphens. Hyphens are not allowed in JavaScript variable names. Use underscores instead.

If you are working with HTML, check the JavaScript Variables in HTML article. It shows how to link variables to web page elements.

Example: Putting It All Together

Here is a complete example that uses all three styles correctly:

// Constants in snake_case
const MAX_RETRIES = 3;
const API_BASE_URL = "https://api.example.com";

// Variables and functions in camelCase
let userName = "Charlie";
let userAge = 28;
let isLoggedIn = false;

function getUserProfile(name) {
  return `Profile for ${name}`;
}

// Class in PascalCase
class User {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

  greet() {
    console.log(`Hello, I am ${this.name}`);
  }
}

// Usage
let currentUser = new User(userName, userAge);
currentUser.greet();
console.log(getUserProfile(userName));

Output of the above code:

Hello, I am Charlie
Profile for Charlie

Notice how each style has a clear purpose. The code is easy to read and understand.

When to Use Each Style

Here is a quick reference table:

StyleWhen to UseExample
camelCaseVariables, functions, methodslet myVariable, function doSomething()
snake_caseConstants, database fields, external APIsconst MAX_VALUE, user_id
PascalCaseClasses, constructors, React componentsclass MyComponent, function Car()

Understanding variable types also helps with naming. The JavaScript Variable Types Guide explains the different data types and how they affect naming.

Conclusion

Choosing the right case style makes your JavaScript code cleaner and more professional. Use camelCase for most variables and functions. Use PascalCase for classes. Use snake_case sparingly for constants or when required by external systems.

Always be consistent. Pick a style and stick with it throughout your project. Your future self and your teammates will thank you. Good naming is a simple habit that has a huge impact on code quality.