Case Conversion in Code: camelCase, snake_case, PascalCase Explained
Every programming language has naming conventions. This guide explains when to use camelCase, snake_case, PascalCase, kebab-case, and SCREAMING_SNAKE_CASE.
Every programming language has its own naming conventions. Using the wrong case for variables, classes, or constants isn't just a style issue โ in some languages and frameworks, it can cause runtime errors or prevent your code from working at all.
camelCase: JavaScript and Java Standard
First word lowercase, subsequent words start with uppercase. No separators. getUserProfile, isLoggedIn, fetchApiData
- JavaScript: variables and functions use camelCase
- Java: methods and variables use camelCase
- Swift: methods and variables use camelCase
PascalCase: Classes and Types
Every word starts with uppercase. No separators. UserProfile, HttpClient, DataRepository
- Classes in JavaScript, Python, Java, C#, TypeScript
- React components (both naming convention and requirement)
- TypeScript interfaces and types
snake_case: Python and Database Standard
All lowercase, words separated by underscores. get_user_profile, is_logged_in, user_id
- Python: all variables, functions, and module names
- SQL: column and table names
- Ruby: methods and variables
kebab-case: CSS and URLs
All lowercase, words separated by hyphens. my-css-class, blog-post-title, user-profile-section
- CSS class names and ID attributes
- URL slugs (blog/how-to-merge-pdf-files-free)
- HTML data attributes (data-user-id)
SCREAMING_SNAKE_CASE: Constants
All uppercase, underscores as separators. MAX_FILE_SIZE, API_BASE_URL, DEFAULT_TIMEOUT_MS
Used for constants in Python, Java, C, and most other languages.