Skip to content

Magic Number

Easy — everyone uses thisGeneral Dev

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.