X Xerobit

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....

Mian Ali Khalid · · 4 min read
Use the tool
Case Converter
Convert text between camelCase, PascalCase, snake_case, kebab-case, SCREAMING_CASE, Title Case, sentence case, and more. Bulk mode.
Open Case Converter →

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

ConventionExampleUsed In
camelCaseuserNameJS variables, Java methods, API keys
PascalCaseUserNameClasses, types, React components
snake_caseuser_namePython, SQL, Ruby
kebab-caseuser-nameCSS, URLs, HTML attributes

Related posts

Related tool

Case Converter

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.