What is camelCase?
camelCase is a naming convention where words are joined together without spaces, with the first word in lowercase and subsequent words capitalized. It's called "camel case" because the capital letters in the middle resemble a camel's humps.
Examples:
firstName
getUserData
totalPriceWithTax
isValidEmailWhen to Use camelCase
- JavaScript/TypeScript: Variable names, function names, method names
- Java: Variable names, method names, parameter names
- C#: Local variables, method parameters, private fields
- Swift: Variables, functions, properties
- Kotlin: Variables, functions, properties
- JSON: Property names in API responses
Examples in Code
JavaScript Variables:
const userName = "John Doe";
const totalItems = 42;
const isLoggedIn = true;Function Names:
function calculateTotalPrice() { }
function getUserById(id) { }
function validateEmailAddress(email) { }JSON API:
{
"firstName": "Jane",
"lastName": "Smith",
"emailAddress": "jane@example.com",
"phoneNumber": "+1234567890"
}camelCase vs PascalCase
While similar, camelCase and PascalCase have an important distinction:
camelCase
First word lowercase
myVariable
getUserData
calculateTotalPascalCase
All words capitalized
MyVariable
GetUserData
CalculateTotalBest Practices
- ✓ Use descriptive names:
userAccountBalanceinstead ofuab - ✓ Start boolean variables with is/has:
isActive,hasPermission - ✓ Use verbs for functions:
getData,calculateTotal - ✓ Be consistent throughout your codebase
- ✗ Don't mix camelCase with other conventions
- ✗ Avoid abbreviations unless widely understood
- ✗ Don't start with uppercase (that's PascalCase)
Language-Specific Guidelines
JavaScript/TypeScript
camelCase is the standard for variables, functions, and methods. Use PascalCase for classes and React components.
const myFunction = () => { }Java
Use camelCase for all variables and methods. Class names use PascalCase.
public void calculateTotal() { }Python
Python typically uses snake_case, but camelCase is common in APIs and certain frameworks.
Why Use camelCase?
- • Readability: Easy to distinguish word boundaries
- • Convention: Standard in most modern languages
- • No spaces: Valid identifier in all programming languages
- • Compact: Shorter than snake_case or kebab-case
- • Consistency: Matches built-in methods (e.g., getElementById)