Can actually understand this challenge

Can someone give me a irl example of where this code could be used and how actually works.I passed the challenge but i try some time now to figure out how it works.Thanks

const createPerson = (name, age, gender) => ({



If you want to return an object from a function probably. Here, you are simply returning an object with an arrow function

createPerson("Dan", 99, undefined);


  name: "Dan",
  age: 99,
  gender: undefined

It’s a function that returns an object, the arguments you pass to the function fill in the relevant properties of the object.

1 Like

i get it,but if you could give me an example that we could use it in a real life project i could understand better the use of this code.

I mean, it’s fairly self-explanatory, I’m not sure I can do that: say you want to create some objects that represent users, you write a function that creates those objects. They could be literally any object that you want to create a few of, “user” is just an example. Just a function that takes some arguments and returns an object – there isn’t really anything more to it than that, it’s quite basic and as I say, self-explanatory: any “real life” code I could write would be literally the same as the example FCC uses. What are you having difficulty with here? I feel like you’re not understanding something, but I’m not quite sure how to give an explanation that makes sense to you

Hello there,

I realise this may not be exactly what you want, but here is some code from the freeCodeCamp repo:

export function buildUserUpdate(
  timezone = getTimezonesOrDefault(isGetDefault)
) {
  const { files } = _completedChallenge;
  let completedChallenge = {};
  if (jsProjects.includes(challengeId)) {
    completedChallenge = {
      files: Object.keys(files)
        .map(key => files[key])
        .map(file =>
          pick(file, ['contents', 'key', 'index', 'name', 'path', 'ext'])
  } else {
    completedChallenge = omit(_completedChallenge, ['files']);
  let finalChallenge;
  const updateData = {};
  const { timezone: userTimezone, completedChallenges = [] } = user;
  const oldChallenge = find(
    ({ id }) => challengeId === id
  const alreadyCompleted = !!oldChallenge;
  if (alreadyCompleted) {
    finalChallenge = {
      completedDate: oldChallenge.completedDate
  } else {
    updateData.$push = {
    finalChallenge = {
  updateData.$set = {
    completedChallenges: uniqBy(
  if (
    timezone &&
    timezone !== 'UTC' &&
    (!userTimezone || userTimezone === 'UTC')
  ) {
    updateData.$set = {
      timezone: userTimezone
  return {
    completedDate: finalChallenge.completedDate

It is a more verbose example, but it is realworld code that accepts properties (user, challengeId, _completedChallenge, timezone), and returns an object literal ({ alreadyCompleted, updateData, completedDate })

Hope this helps