Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

closure

function outer() {
  const outerVar = "Hi i am outerVar";
  function inner() {
    const innerVar = "Hi i am innerVar";
    console.log(outerVar);
    console.log(innerVar);
  }
  return inner;
}

const innerFn = outer();
innerFn(); 
// Hi i am outerVar
// Hi i am innerVar
 
PREVIOUS NEXT
Tagged: #closure
ADD COMMENT
Topic
Name
7+7 =