I appreciate the brevity of the shorthand 🤷
const foo = () => ({ a: 1, b: 2 });
compare that to:
const foo = () => {
return { a: 1, b: 2 };
};
But, I don't think the long-hand ever really bothers me, and can have some real benefits.
Like if something has to change in the future, it makes diffs cleaner.
contrived example:
- const someFn = () => ({
+ const someFn = () => {
- foo: "bar"
+ const bar = "bar";
+ return {
+ foo: bar
+ };
- });
+ };
vs
const someFn = () => {
+ const bar = "bar";
return {
- foo: "bar"
+ foo: bar
};
};
And its easier to throw debugging stuff in, etc...
const someFn = () => {
+ console.log('debugging is fun');
return {
foo: "bar"
};
};
The diffs are less about the shorthand / longhand and more about style.
My only preference for the shorthand is that it's a single expression vs. a series of statements and is thus a simpler grammatical structure (as expressions are statements [in most languages at least that have both]). Adding in debugging info isn't that difficult just minimal work.