-2

I have a bunch of nested functions, some of which return values that I would like to get out to the global scope. What is the best way to do this? This is my example:

function mainFunction(){
      function A(){
            //somecode
            return valueA;
      }
      function B(){
           //somecode
           return {valueB1: valueB1, valueB2: "N/A"};
      }
      return {Avalue: A(), Bvalue: B().valueB1}
}
kennsorr
  • 292
  • 3
  • 20

1 Answers1

1

You may use a block statement and var for stuff you want to share and let/const for private things:

{
 //private
 const func1 = function(){
   return "works";
 };
 //public
 var result1 = func1();
}

So you can access

console.log(result1);

but not the function itself.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151