Meaningful Naming

// Uses clear, descriptive names for variables, functions, and classes

Best PracticesCode QualityNaming
Highly Rated
Community Verified

// detailed.guidelines

# Meaningful Naming

Use names that reveal intent and make code self-documenting.

## Variables

```javascript
// Bad
const d = 86400000;
const x = users.filter(u => u.a);

// Good
const MILLISECONDS_PER_DAY = 86400000;
const activeUsers = users.filter(user => user.isActive);
```

## Functions

```javascript
// Bad
function proc(data) { }
function get() { }
function do() { }

// Good
function processPayment(transaction) { }
function getUserById(id) { }
function validateEmailFormat(email) { }
```

## Use Verb-Noun Pattern

```javascript
// Functions should do something
getUserData()
calculateTotal()
sendNotification()
validateInput()

// Booleans should ask questions
isValid()
hasPermission()
canEdit()
shouldRetry()
```

## Avoid Abbreviations

```javascript
// Bad
const usrCnt = users.length;
const msg = "Hello";

// Good
const userCount = users.length;
const message = "Hello";
```

## Be Consistent

Use the same terminology throughout your codebase.

If you use `fetch` in one place, don't use `get`, `retrieve`, or `load` for similar operations elsewhere.

## Length vs Scope

- Short scopes can have shorter names: `i` in a loop
- Long scopes need descriptive names
- Global variables need very descriptive names