I am unable to understand how does this logic work? Like we pass certain arguments to a function then what happens? how does the system know if we have passed the arguments for the keys or the values?
**Your code so far**
const createPerson = (name, age, gender) => {
// Only change code below this line
return {
name,
age,
gender
};
// Only change code above this line
};
Challenge: Write Concise Object Literal Declarations Using Object Property Shorthand
Link to the challenge:
This createPerson
function takes three arguments: name
, age
, and gender
. I’m assuming name
and gender
are strings and age
is a number. The system doesn’t know anything else about them other than that. You are creating and returning an object with the three properties name
, age
, and gender
and assigning each of these properties their respective values passed into the function. You are telling the system what to do.
Remember, you can write the property/values using the traditional long form:
return {
name: name,
age: age,
gender: gender
}
This challenge is asking you to convert that the shorthand form, but you are still doing the same thing.
1 Like
The name of the variable is the key and the value the variable contains will be the value.
const name = 'John';
const age = 32;
const user = {
name,
age
}
user.name // John
user.age // 32
Thanks, it gave me a bit clarity on the issue.