0

In JavaScript, is there a workaround to achieve the following:

const people = {
    mom: {
        id: "Jane",
    },
    child: {
        id: "Jack"
        // The problem
        // Can't access people here, because at this stage,
        // the object has not yet been initialised
        parentId: people.mom.id 
    },
};

The problem:

Uncaught ReferenceError: Cannot access 'people' before initialization

Ben
  • 14,557
  • 16
  • 84
  • 127

0 Answers0