Naming, Readability, and Common Pitfalls
Naming and readability guidelines; avoid shadowing, magic numbers, and mixed declarations.
Naming, Readability, and Common Pitfalls is a free JavaScript Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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

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 guidelines
Naming tips:
- Nouns for data (userName, totalPrice)
- Verbs for functions (computeTotal)
- Be consistent with casing (camelCase)

No magic numbers
Promote fixed values to constants (UPPER_CASE is common). It explains intent and eases updates.
// Replace magic numbers with named constants
const TAX_RATE = 0.08;
const SUBTOTAL = 20;
const tax = SUBTOTAL * TAX_RATE;
const finalTotal = SUBTOTAL + tax;
console.log("Tax:", tax);
console.log("Final total:", finalTotal);

Shadowing demo
Shadowing: An inner variable uses the same name and hides the outer one. Prefer unique names when scopes nest.
// Shadowing: inner variable hides an outer one
let score = 10;
function addBonus() {
// The next line creates a new "score" only inside this function
let score = 5;
console.log("Inner score:", score);
}
addBonus();
console.log("Outer score:", score);

Readability checklist
Checklist:
- One idea per line
- Short functions
- Use constants for fixed values
- Avoid reused names across scopes

Naming best practice quiz
Quick check: Clear naming.

Recap
Recap: Use descriptive names, promote fixed values to constants, and avoid shadowing to keep code easy to read and maintain.

Frequently asked questions
Is the “Naming, Readability, and Common Pitfalls” lesson free?
Yes — the full text of “Naming, Readability, and Common Pitfalls” is free to read here on the web, and the JavaScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Naming, Readability, and Common Pitfalls”?
Naming and readability guidelines; avoid shadowing, magic numbers, and mixed declarations. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Naming, Readability, and Common Pitfalls” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- let, const, and avoiding var
- Block/Function/Module Scope and the TDZ
- Naming, Readability, and Common Pitfalls