Clean Code JavaScript – Naming Patterns
Table of Contents
- Principles
- Variables
- Functions
- Booleans
- Bad vs Good Examples
Principles
- Names should reveal intent
- Avoid abbreviations and mental mapping
- Use domain language consistently
Variables
// ❌ Bad
const d = 86400000;
// ✅ Good
const MILLISECONDS_PER_DAY = 86400000;
Functions
// ❌ Bad
function getUser(u) {}
// ✅ Good
function fetchUserById(userId) {}
Booleans
// ❌ Bad
if (!user.isNotActive) {}
// ✅ Good
if (user.isActive) {}
Bad vs Good Examples
// ❌ Bad
const data = getData();
// ✅ Good
const usersResponse = fetchUsers();