Don't understand brackets in arrow functions

I wanted to play around with composition in JS, eg:

Problem: in composition there is used a special arrow syntax with brackets, see (2) in code.
I have an idea how to use it in context of composition.
But I don’t really understand what the bracket are doing. What is the exact functionality of () in arrow notation?

// (1) normal arrow function
const goo = () => console.log(12);
goo(); // 12


// (2) special syntax with extra brackets ???
const moo = () => ({do:()=>console.log(34)});

console.log(moo); // () => ({do:()=>console.log(34)})

// moo() gives me an object:
console.log(moo()); // Object { do: () => console.log(34) } 

// I can call do() on that object
moo().do(); // 34

It is because if you do the implicit return you need to wrap the function in round brackets or it would consider what’s inside the graph brackets as the function body

1 Like

ah ok, thanks.

without (…) there is missing a return
and with return I don’t need (…):

// (3) with return
const boo = () => {return {do:()=>console.log(34)}};
console.log(boo()); // Object { do: () => console.log(34) }
boo().do(); // 34

Exactly, the implicit return is used to make functions even more compact for simple logic, but if you need to return an object you need round brackets to wrap it or it will consider the graph brackets as function body