ES6 - Write Concise Object Literal Declarations Using Object Property Shorthand

Tell us what’s happening:
Describe your issue in detail here.

I solved this with the code below (which seems to make more sense to me and is awarded a correct solution). Is this correct? The solution provided in the Hint seems to be too long for nothing.

Your code so far

const createPerson = (name, age, gender) => ({name, age, gender});

Your browser information:

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

Challenge: ES6 - Write Concise Object Literal Declarations Using Object Property Shorthand

Link to the challenge:

You are absolutely correct. Your code can also be re-written as
const createPerson = (name, age, gender) => ({ name: name, age: age, gender: gender })
which still means the same thing but your code is shorter and more concise. Nice solution

1 Like

it’s correct. I imagine the solution in the hints changed much less from the seed code, using the explicit return statement

Thanks! I appreciate the reply.

Is there a reson for including?..

({ name: name, age: age, gender: gender})

instead of…

({ name, age, gender })

…it seems redundent.

It all depends upon the style guide of your project. That’s two different ways to write the same thing.

ok. Thanks. Good to know.

In addition to what @JeremyLT said, your solution is an ES6 feature.