Using Array.map() for side effects leads to confusing code and unnecessary memory usage.
Many developers use map() like this:
users.map(user => {
console.log(user.name);
});This is wrong.
map() is meant to transform data, not execute side effects.
Problem:
- Creates a new unused array
- Misleads other developers
- Wastes memory in large datasets
Correct approach:
users.forEach(user => {
console.log(user.name);
});Pro Insight:
Use:
map()→ transformforEach()→ side effects
Clean code = better maintainability.
More Daily Dev Tips
Don’t Hide Errors Behind Generic Toasts
A “Something went wrong” message helps nobody. Log the real error and show users what they can do next.
💡Always Add Timeouts to External API Calls
Never call external APIs without a timeout — one slow dependency can freeze your entire system.
💡Validate Request Payloads at the API Boundary
Never trust incoming request data. Validate it at the API boundary before it touches business logic or the database.
Get a new Daily Dev Tip in your inbox
Subscribe to Stack Dev Life — free, no spam, unsubscribe anytime.
Subscribe free →