-1

I am trying to grasp the concept of closure function in javascript. Below is a simple code.Need to pass an argument of "inside" to the innerFunction. how do i do it.

     function outerFunction(outerVariable){
         function innerFunction(innerVariable){
                  console.log("Outer Variable" +" = "+ outerVariable);
                  console.log("Inner Variable" +" = "+ innerVariable);
        }
        return innerFunction;
      };

     const newOutFunction = outerFunction("outside");

     newOutFunction();
new2coding
  • 27
  • 1
  • 7
  • 5
    since `outerFunction` returns the inner function (which you then store in `newOutFunction`), you can pass arguments into it using: `newOutFunction("inside")` – Nick Parsons Jul 17 '20 at 07:03

1 Answers1

0

Do you mean this?

     function outerFunction(outerVariable){
     function innerFunction(innerVariable){
              console.log("Outer Variable" +" = "+ outerVariable);
              console.log("Inner Variable" +" = "+ innerVariable);
    }
    return innerFunction;
  };

 const newOutFunction = outerFunction("outside");
 let new_var = "inside"
 newOutFunction(new_var);
Dmytro Huz
  • 1,514
  • 2
  • 14
  • 22