camelCase vs snake_case: The Developer's Complete Guide
By caseconvert.me team
If you have spent any time writing code, you have faced this decision dozens of times: should this variable be getUserData or get_user_data? Should this function be calculateTotal or calculate_total?
The answer is not always obvious — and it depends heavily on the language you are working in, the team conventions you are following, and sometimes the specific context within a single project.
This guide breaks down camelCase vs snake_case completely: what each one is, which languages prefer which, when to use each, and how to convert between them instantly.
What is camelCase?
camelCase is a naming convention where words are joined together without spaces or separators, with the first word in lowercase and each subsequent word starting with an uppercase letter. The name comes from the way the capitalised letters resemble the humps of a camel. Examples:
getUserData backgroundColor isLoggedIn calculateTotalPrice fetchUserProfileById
There are two variants worth knowing. The standard version — where the first word is lowercase — is sometimes called lowerCamelCase or dromedaryCase. The variant where every word including the first starts with a capital letter (UserProfile, GetData) is called UpperCamelCase or PascalCase, and is treated as a separate convention.
What is snake_case?
snake_case is a naming convention where all letters are lowercase and words are separated by underscores. The name comes from the way underscores lie flat on the baseline, like a snake on the ground. Examples:
get_user_data first_name background_color is_logged_in calculate_total_price fetch_user_profile_by_id
There is also SCREAMING_SNAKE_CASE — the same convention but with all uppercase letters. This is used specifically for constants and environment variables: DATABASE_URL, MAX_RETRY_COUNT, API_SECRET_KEY.
camelCase vs snake_case: Side-by-Side Comparison
| Feature | camelCase | snake_case | SCREAMING_SNAKE |
|---|---|---|---|
| Separator | None (caps) | Underscore | Underscore |
| First letter | Lowercase | Lowercase | Uppercase |
| Readability | Good | Very good | Good (constants) |
| Typing speed | Fast | Slightly slower | Slower |
| URL-safe? | Yes | Yes | Yes |
| Case-sensitive? | Yes | Yes | Yes |
Which Languages Use camelCase?
camelCase is the dominant convention in most object-oriented and C-style languages. If you are working in any of the following, camelCase is almost certainly the expected standard:
| Language | camelCase Used For | Example |
|---|---|---|
| JavaScript | Variables, functions, object keys | const getUserData = () => {} |
| TypeScript | Variables, functions, interfaces (lower) | let firstName: string |
| Java | Variables, methods | public void getUserData() |
| Swift | Variables, functions, properties | var userName: String |
| Kotlin | Variables, functions | fun getUserProfile(): User |
| Dart / Flutter | Variables, functions | String firstName |
| JSON | Object keys (by convention) | { "userId": 1 } |
Which Languages Use snake_case?
snake_case is the standard in Python, Ruby, and most database contexts. It is also the default for file naming in many ecosystems:
| Language / Context | snake_case Used For | Example |
|---|---|---|
| Python | Variables, functions, modules (PEP 8) | def get_user_data(): |
| Ruby | Variables, methods, symbols | def get_user_profile |
| SQL | Column names, table names | user_id, created_at |
| PostgreSQL / MySQL | All identifiers | SELECT first_name FROM users |
| Rust | Variables, functions | fn get_user_data() -> User |
| PHP | Variables, functions (PSR-12) | $user_name, get_user_data() |
| File naming | Python scripts, config files | user_profile.py, api_config.json |
The JavaScript Special Case: Both at Once
JavaScript projects often use both conventions simultaneously — and this causes the most confusion for developers. Here is the standard breakdown for a typical JavaScript or Node.js project:
// Variables and functions → camelCase
const getUserData = async (userId) => {
const firstName = user.firstName;
return firstName;
};
// Classes and React components → PascalCase
class UserProfile extends Component {}
const NavBar = () => <nav />;
// Constants → SCREAMING_SNAKE_CASE
const MAX_RETRY_COUNT = 3;
const API_BASE_URL = process.env.API_BASE_URL;
// CSS class names and HTML attributes → kebab-case
// <div class='nav-bar' data-user-id='1'>When working with a Python backend and a JavaScript frontend, you will often need to convert between conventions. A Python API returns snake_case JSON keys (user_id, first_name), while your JavaScript frontend expects camelCase (userId, firstName). Many teams handle this with a serialisation layer — or use a converter tool to quickly check their naming.
Python: Why snake_case Is Non-Negotiable
Python has an official style guide — PEP 8 — that explicitly defines naming conventions. For most Python developers, following PEP 8 is not optional: it is expected by the community, enforced by linters (pylint, flake8), and required by most open-source contribution guidelines
# PEP 8 compliant Python
def calculate_total_price(item_price, quantity):
total_price = item_price * quantity
return total_price
# Non-compliant (would fail a linter)
def calculateTotalPrice(itemPrice, quantity):
totalPrice = itemPrice * quantity
return totalPriceThis is one of the most common sources of frustration for developers moving from JavaScript to Python — the muscle memory for camelCase keeps firing in a codebase that expects snake_case. Tools that convert between the two are genuinely useful for this transition period.
Quick Reference: When to Use Which
| Situation | Use camelCase | Use snake_case |
|---|---|---|
| JavaScript variable | userName | user_name |
| Python function | getUserData() | get_user_data() |
| SQL column | userId | user_id |
| React prop | onClick, isVisible | on_click, is_visible |
| Python module name | UserProfile | user_profile |
| Environment variable | apiSecretKey | API_SECRET_KEY |
| JSON API response key | firstName (JS APIs) | first_name (Python APIs) |
How to Convert Between camelCase and snake_case
Converting between the two is a common task when working across language boundaries. You can do it manually, write a quick function, or use an online converter.
JavaScript function to convert camelCase to snake_case:
const camelToSnake = (str) =>
str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
camelToSnake('getUserData'); // 'get_user_data'
camelToSnake('firstName'); // 'first_name'
camelToSnake('isLoggedIn'); // 'is_logged_in'
Python function to convert snake_case to camelCase:
def snake_to_camel(name):
components = name.split('_')
return components[0] + ''.join(x.title() for x in components[1:])
snake_to_camel('get_user_data') # 'getUserData'
snake_to_camel('first_name') # 'firstName'
snake_to_camel('is_logged_in') # 'isLoggedIn'
Or use the free converter at caseconvert.me — paste your text, click camelCase or snake_case, and copy the result instantly.
The camelCase vs snake_case debate is not really a debate — it is a context question. The right answer depends entirely on the language, the framework, and the team conventions you are working within.
The simple rule: follow the language's official style guide. Use camelCase in JavaScript, Java, and Swift. Use snake_case in Python, Ruby, and SQL. When working across language boundaries, know how to convert between them quickly.
If you work across multiple languages daily, bookmark caseconvert.me — it converts between all case formats instantly, with no signup required.
Convert between camelCase and snake_case instantly → caseconvert.me
Use the Free Converter →