Programming style question: say I'm returning a value that is conditional on a flag, in JavaScript. Is it better to return a conditional value (return bool ? this : that) or conditionally return a value (bool ? return this : return that) and why do you think this?

return b ? x : y;
says "Here's where I return something, and here's what it is: a ternary expression.".

The other option is just a minified `if...else`. Sometimes you need to return inside a conditional, but I'd prefer not to. Having a single place where you return (or as few as possible) is nice.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!