Curly brackets vs parentheses in arrow function declaration

Hi guys,

I’ve just finished lesson “Write Concise Object Literal Declarations Using Object Property Shorthand” and in the explanation and example by fCC, I don’t understand one thing.
Why there are normal parentheses around the object, and not the curly brackets as with any other function declaration?

fCC example:

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

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

Thank you!

Challenge: Write Concise Object Literal Declarations Using Object Property Shorthand

Link to the challenge:

MDN to the rescue!

Ook, so when I want to return an object from an arrow function and I omit the keyword return, then I have to add the parentheses?

Did I understand it right?

1 Like

You got it! The arrow function first thinks {function body} when it sees {}, not {object definition}.

1 Like

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