Lesson 10 / 25
Common Code Quality Issues
Detect and fix common mistakes ESLint catches.
Common pitfalls
Unused variables (no-unused-vars), undefined variables (no-undef), unnecessary variables (no-var), and missing semicolons are the top issues ESLint catches.
Before and after
Code with issues (left) vs. ESLint-compliant code (right).
// BEFORE (issues)
var x = 5;
let result = x + y; // y undefined, x unused
console.log(result)
// AFTER (fixed)
const result = 5 + 10;
console.log(result);
Output:
Fixed: removed unused var x, defined y, added semicolon
Auto-fix when possible
Run eslint --fix to automatically correct many issues. But review changes—some fixes require manual intervention.
Quick check
Quick check: What does 'no-undef' rule catch?
- Variables used without being defined.
- Variables that are never used.
- Functions without return statements.
Answer
Variables used without being defined. — 'no-undef' prevents runtime errors by catching undefined variable references before the code runs.