Hugo Almeida
Hugo Almeida

Reputation: 105

Getting an object property defined in a function

I just defined object and it's property inside a function:

function objectDefinition() {
      const object = {
            property: value
      }
}

How can I get it from outside the function? Would something like the code below work?

object = {}

function objectDefinition() {
      const object = {
            property: value
      }
}

If it doesn't work, is there any other way?

Upvotes: 0

Views: 31

Answers (1)

Barmar
Barmar

Reputation: 781726

You should return the object from the function.

function objectDefinition() {
  const object = {
        property: value
  }
  return object;
}

let someVar = objectDefinition();

Upvotes: 2

Related Questions