Why do we use parentheses here?

Why do we use parentheses here? NOT red color. The parentheses at he end of the function.

const getMousePosition = (x, y) => ({ x, y });

Why not like this:

const getMousePosition = (x, y) => { x, y };
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Write Concise Object Literal Declarations Using Object Property Shorthand

Link to the challenge:

What happens when you try it?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#returning_object_literals

1 Like

Thanks for the link! :pray:
Oke I think I understand it, it doesn’t treat it as a object. So the output of the function is not a object if you don’t use the parenthesis. Correct?

2 Likes

Yup. Just {} means that you are making a function body that requires the return keyword.

1 Like

Thank you @JeremyLT ! :pray: