Tell us what’s happening:
I understand what the code does, but I don’t entirely get how it’s written. I’ll try to explain.
First of all, I passed the challenge referencing the example (the function getMousePosition
), which looks slightly different from the solution given. What I don’t understand is the use of the parenthesis both in the example and in my solution: shouldn’t an arrow function use braces after the arrow? If I’m not wrong it’s the first time I see it written this way.
Does the parenthesis substitute the return
keyword? The solution given uses braces and the return
keyword.
Your code so far
const createPerson = (name, age, gender) => ({
name,
age,
gender
});
console.log(createPerson('marco', 34, 'm'));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:78.0) Gecko/20100101 Firefox/78.0
.
Challenge: Write Concise Object Literal Declarations Using Object Property Shorthand
Link to the challenge: