# Common Code Quality Issues — ESLint and Prettier: Code Quality and Formatting

Source: https://www.skillbyai.com/en/eslint-prettier/eslint-prettier-10

> Spot and fix common issues ESLint catches, such as unused and undefined variables and var usage.

## 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).

```javascript
// 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

**Quiz:** What does 'no-undef' rule catch?

- [ ] Variables that are never used.
- [ ] Functions without return statements.
- [ ] Missing semicolons only
- [x] Variables used without being defined.

*Answer:* Variables used without being defined.. 'no-undef' prevents runtime errors by catching undefined variable references before the code runs.
