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?


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?


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

1 Like

Thank you @JeremyLT ! :pray:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.