ES6 - Write Concise Object Literal Declarations Using Object Property Shorthand

Tell us what’s happening:
Describe your issue in detail here.
I have finished the challenger but I don’t know in what case we use these types of function

Your code so far

const createPerson = (name, age, gender) => ({
  // Only change code below this line
  name,age,gender
  // Only change code above this line
});

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

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

Link to the challenge:

the description of this challenge states:

ES6 provides the syntactic sugar to eliminate the redundancy of having to write x: x

The phrase “syntactic sugar” here means that this is a style of writing code that shortens how much typing you need to do in order to accomplish the task.
You should understand it because you may need to read code one day that uses this method of writing objects properties.

Another example of syntactic sugar you may have seen before is this:
i++ vs i = i+1
The shorter version is common and does exactly the same thing as the longer statement.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.