DEV Community

Raja B
Raja B

Posted on

JavaScript Naming Conventions

Programming has many naming conventions used to write clean and readable code

Style Example
camelCase firstName
PascalCase FirstName
snake_case first_name
UPPER_SNAKE_CASE MAX_SIZE
kebab-case first-name
Train-Case First-Name
flatcase firstname
UPPERCASE FIRSTNAME
camel_Snake_Case first_Name

Most Common Styles:

1. camelCase:

firstName
mobileNumber

Used for:

  • Variables

  • Functions

2. PascalCase:

FirstName
StudentDetails

Used for:

  • Classes

  • Components

3. snake_case:

first_name
mobile_number

Common in:

  • Python

  • Databases

4. UPPER_SNAKE_CASE:

MAX_SIZE
PI_VALUE

Used for:

  • Constants

5. kebab-case:

first-name
user-profile

Used for:

  • URLs

  • CSS class names

In JavaScript, you cannot use first-name as a variable name because the-(hyphen) is interpreted as the minus operator.

 Error:

let first-name = "Raja"; 
Enter fullscreen mode Exit fullscreen mode

Rule: Variable names can contain letters, numbers, _ (underscore), and $, but not - (hyphen)

Top comments (0)