0Pricing
JavaScript Academy · Lesson

Naming, Readability, and Common Pitfalls

Naming and readability guidelines; avoid shadowing, magic numbers, and mixed declarations.

Intro

Goal: Write readable code. Use clear names, avoid magic numbers, and be careful with shadowing.

  • Descriptive names
  • Constants for fixed values
  • No accidental shadowing
Naming, Readability, and Common Pitfalls — illustration 1

Clear naming demo

Name variables for what they hold, not how they are used. Short but clear wins.

// Use descriptive names
// Avoid single letters or vague words
const itemCount = 3;
const unitPrice = 5;

const totalPrice = itemCount * unitPrice;

console.log("Items:", itemCount);
console.log("Unit price:", unitPrice);
console.log("Total price:", totalPrice);
Naming, Readability, and Common Pitfalls — illustration 2

All lessons in this course

  1. let, const, and avoiding var
  2. Block/Function/Module Scope and the TDZ
  3. Naming, Readability, and Common Pitfalls
← Back to JavaScript Academy