camelCase — What It Is and Where to Use It in Programming
camelCase capitalizes the first letter of each word except the first: helloWorld, getUserProfile. It's the standard for JavaScript variables, Java methods, and API JSON keys....
camelCase (lowerCamelCase) capitalizes the first letter of each word except the first, with no separators: helloWorld, getUserProfile, isLoggedIn. It’s named after how the bumps resemble a camel’s humps.
Use the Case Converter to convert any text to camelCase instantly.
camelCase rules
user name → userName
get user profile → getUserProfile
First Name → firstName
HTTP Request → httpRequest (or hTTPRequest — varies by style guide)
- First word is all lowercase
- First letter of each subsequent word is capitalized
- No spaces, underscores, or hyphens
- Numbers are allowed:
sha256Hash,oauth2Token
Where camelCase is standard
JavaScript and TypeScript variables and functions
ECMAScript (and every major JS style guide) mandates camelCase for variables and functions:
// Variables:
const userName = 'Alice';
let isAuthenticated = false;
const maxRetryCount = 3;
// Functions:
function getUserProfile(userId) { ... }
const calculateTotalPrice = (items, taxRate) => { ... };
const handleSubmit = async (event) => { ... };
// Object properties:
const user = {
firstName: 'Alice',
lastName: 'Smith',
emailAddress: 'alice@example.com',
createdAt: new Date(),
};
React event handlers and props
// Event handlers: camelCase
function LoginForm() {
const handleInputChange = (e) => { ... };
const handleFormSubmit = async (e) => { ... };
return (
<form onSubmit={handleFormSubmit}>
<input onChange={handleInputChange} />
<button onClick={() => setIsLoading(true)}>Submit</button>
</form>
);
}
// Component props: camelCase
<UserCard
firstName="Alice"
lastName="Smith"
isActive={true}
onProfileClick={handleProfileClick}
/>
Java methods and variables
Java uses camelCase for methods and local variables:
// Variables:
String firstName = "Alice";
int maxRetryCount = 3;
boolean isAuthenticated = false;
// Methods:
public UserProfile getUserProfile(int userId) { ... }
public void calculateTotalPrice(List<Item> items) { ... }
private boolean validateCredentials(String email, String password) { ... }
// Method parameters:
public void createUser(String firstName, String lastName, String emailAddress) { ... }
JSON API keys
REST APIs typically return camelCase JSON:
{
"userId": 123,
"firstName": "Alice",
"lastName": "Smith",
"emailAddress": "alice@example.com",
"isEmailVerified": true,
"createdAt": "2026-05-11T10:00:00Z",
"lastLoginAt": "2026-05-11T12:30:00Z"
}
This matches JavaScript usage — when you access response.data.firstName, you don’t need to convert from snake_case.
Swift and Kotlin
iOS and Android development also use camelCase:
// Swift:
var userName: String = "Alice"
var isLoggedIn: Bool = false
func getUserProfile(userId: Int) -> UserProfile { ... }
func calculateDiscount(originalPrice: Double, rate: Double) -> Double { ... }
// Kotlin:
val userName: String = "Alice"
var isLoggedIn: Boolean = false
fun getUserProfile(userId: Int): UserProfile { ... }
Converting to camelCase in code
JavaScript
function toCamelCase(str) {
return str
.toLowerCase()
.replace(/[-_\s]+(.)/g, (_, char) => char.toUpperCase());
}
toCamelCase('user-name'); // 'userName'
toCamelCase('user_first_name'); // 'userFirstName'
toCamelCase('Hello World'); // 'helloWorld'
toCamelCase('PascalCase'); // 'pascalcase' (P lowercased, then 'case')
// Better version handling more edge cases:
function toCamelCaseRobust(str) {
const words = str.split(/[-_\s]+/);
return words
.map((word, i) => {
if (i === 0) return word.toLowerCase();
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
})
.join('');
}
toCamelCaseRobust('first_name'); // 'firstName'
toCamelCaseRobust('get-user-data'); // 'getUserData'
toCamelCaseRobust('HELLO WORLD'); // 'helloWorld'
Transforming API response keys
// Convert snake_case API response to camelCase:
function keysToCamelCase(obj) {
if (Array.isArray(obj)) {
return obj.map(keysToCamelCase);
}
if (obj !== null && typeof obj === 'object') {
return Object.entries(obj).reduce((acc, [key, value]) => {
const camelKey = key.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
acc[camelKey] = keysToCamelCase(value);
return acc;
}, {});
}
return obj;
}
keysToCamelCase({ user_name: 'Alice', first_name: 'Alice', created_at: '2026' });
// { userName: 'Alice', firstName: 'Alice', createdAt: '2026' }
Python
import re
def to_camel_case(name: str) -> str:
words = re.split(r'[-_\s]+', name)
return words[0].lower() + ''.join(w.capitalize() for w in words[1:])
to_camel_case('user_name') # 'userName'
to_camel_case('get-user-data') # 'getUserData'
to_camel_case('Hello World') # 'helloWorld'
Handling acronyms in camelCase
Style guides differ on how to handle acronyms:
// Option 1: Treat acronyms as words (Google style):
xmlParser // xml is a word
httpRequest // http is a word
htmlElement // html is a word
// Option 2: Keep acronyms as caps (Microsoft style):
XMLParser
HTTPRequest
HTMLElement
Pick one and be consistent. Most modern style guides (Airbnb, Google) prefer treating acronyms as words.
camelCase vs other conventions
| Convention | Example | Used In |
|---|---|---|
| camelCase | userName | JS variables, Java methods, API keys |
| PascalCase | UserName | Classes, types, React components |
| snake_case | user_name | Python, SQL, Ruby |
| kebab-case | user-name | CSS, URLs, HTML attributes |
Related tools
- Case Converter — convert between naming conventions
- camelCase vs snake_case — when to use each
- Naming Conventions Guide — language-specific rules
Related posts
- camelCase vs snake_case — Which Naming Convention to Use and When — camelCase and snake_case are the two dominant naming conventions in programming.…
- Kebab Case — What It Is and Where to Use kebab-case — Kebab case uses hyphens between lowercase words: hello-world, user-first-name. I…
- PascalCase — What It Is and Where to Use It in Code — PascalCase capitalizes the first letter of every word with no separators: HelloW…
- Programming Naming Conventions — camelCase, PascalCase, snake_case by Language — Different programming languages have different naming convention standards. Here…
Related tool
Convert text between camelCase, PascalCase, snake_case, kebab-case, SCREAMING_CASE, Title Case, sentence case, and more. Bulk mode.
Written by Mian Ali Khalid. Part of the Dev Productivity pillar.