For this exercise, if you follow the instruction of “Only change code below/above this line”, your code won’t work. You have to change the first and last curly braces to parentheses to succeed.
The execise:
Use object property shorthand with object literals to create and return an object with name , age and gender properties.
const createPerson = (name, age, gender) => {
// Only change code below this line
return {
name: name,
age: age,
gender: gender
};
// Only change code above this line
};
My solution:
const createPerson = (name, age, gender) => (
// Only change code below this line
{name, age, gender}
// Only change code above this line
);
this is also the first time in the course we encounter parenthesis wrapped around a function body with no clear explanation as to why it’s there and what it’s for.
oooh okay I see. So if I understand you correctly the parenthesis returns the statement within the body?
thank you! I haven’t encountered the terminology of “implicit” and “explicit” yet. Just knowing the words helps clarify the concepts!
if you want to return an empty object you can’t write () => {} as that is an empty function body, situation as the first case, where the graph parentheses surround the function body
so to identify that it is not a function body but you are using implicit return to return an object you put the object inside round parenthesis