Concise Object Literal Declarations Using Simple Fields doubt

Concise Object Literal Declarations Using Simple Fields doubt
0

#1

Tell us what’s happening:

i don’t understand whats special about this" simple fields with object literals".
what i see is that we passed name,age,gender as argument and returning them so const createPerson contains a array of three elements.

Your code so far


const createPerson = (name, age, gender) => {
  "use strict";
  // change code below this line
  return {
    name,
    age,
    gender
  };
  // change code above this line
};
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-concise-object-literal-declarations-using-simple-fields


#2

That means that, in ES6, instead of:

{
  name: name,
  age: age,
  gender: gender
};

You can make it simple by doing this:

{
  name,
  age,
  gender
};

It’s worth noting that only key/value pairs with the same value apply to this. E.g.: { name: Name } won’t work as { name }.


#3

createPerson is a function and not an array. This function returns an object with three properties (name, age and gender).


#4

if it was “return [name,age,gender]” then createPerson will be array …right ?


#5

Yes that would be an array.