Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/write-concise-object-literal-declarations-using-object-property-sh

Why is it in brackets???

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

I mean this

({ x, y })

Your browser information:

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

Challenge: Write Concise Object Literal Declarations Using Object Property Shorthand

Link to the challenge:

this is the object we want to return from the function

if we write (x,y) => {x, y} the {} are interpreted as being those around the function body, so to make the function return an object using implicit return we need to surround it with (), making it (x,y) => ({x, y})

1 Like