What is PascalCase?
PascalCase is a naming convention where the first letter of each word is capitalized, with no spaces or separators between words. Unlike camelCase, PascalCase capitalizes the first letter of the first word as well.
Examples:
UserAccount
GetUserData
TotalPriceCalculator
EmailValidatorWhen to Use PascalCase
- Class names: In most object-oriented languages
- React components: Functional and class components
- Type definitions: TypeScript interfaces and types
- Constructors: Constructor functions in JavaScript
- Enums: Enumeration names
- Namespaces: In languages that support them
Examples in Code
React Component:
function UserProfile() {
return <div>Profile</div>;
}TypeScript Interface:
interface UserAccount {
firstName: string;
lastName: string;
emailAddress: string;
}Class Definition:
class EmailValidator {
validate(email) {
// validation logic
}
}PascalCase vs camelCase
The only difference is the first letter:
PascalCase: UserAccount - First letter capitalized
camelCase: userAccount - First letter lowercase
Best Practices
- ✓ Use for all class and component names
- ✓ Apply to TypeScript interfaces and types
- ✓ Maintain consistency across your codebase
- ✓ Use descriptive names that indicate purpose
- ✗ Don't use for variable or function names
- ✗ Avoid mixing with camelCase for classes