Do Parentheses Matter in Arrow Functions? A TypeScript Deep Dive
dev.to·5h·
Discuss: DEV
Flag this post

Understanding when parentheses change behavior and when they’re just style


You’re writing a map function in TypeScript, and you wonder: “What if I put parentheses around the return value? Would that affect anything?”

This seemingly simple question touches on some fundamental JavaScript/TypeScript syntax rules that can trip up even experienced developers. Let me break down exactly when parentheses matter in arrow functions—and when they don’t.

The Question That Started It All

Imagine you have this code:

const housesToSyncIDs = housesToSync.map((h) => h.id);

And you’re wondering: “What if I write it like this?”

const housesToSyncIDs = housesToSync.map((h) => (h.id));

Does it make a difference? The short answer: No, it doesn’t. But unders…

Similar Posts

Loading similar posts...