Magic Number
ELI5 — The Vibe Check
A random number in your code with no explanation. Like writing if (age > 17) instead of if (age > MINIMUM_AGE). Nobody knows why it's 17, where it came from, or what it means. Always use named constants instead!
Real Talk
A magic number is a numeric literal in code that has no obvious meaning. It's considered an anti-pattern because it reduces readability and makes maintenance harder. The fix is to extract it into a named constant.
Show Me The Code
// Bad - magic number:
if (retries > 3) { ... }
// Good - named constant:
const MAX_RETRIES = 3
if (retries > MAX_RETRIES) { ... }
When You'll Hear This
"What does the 86400 mean? That's a magic number — use SECONDS_IN_DAY instead."
Related Terms
Code Smell
Code that works but feels... wrong. Like when food smells slightly off — it might be fine, but something isn't right.
Constant
A constant is a box you seal shut after putting something in. You can look inside any time you want, but you can't swap out what's in there.
Refactoring
Refactoring is improving the internal structure of code WITHOUT changing what it does from the outside.