Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js closure examples

function outer() {
  var counter = 0; // Backpack or Closure
  function incrementCounter() {
    return counter++;
  }
  return incrementCounter;
}

const count = outer();
count(); // 0
count(); // 1
count(); // 2
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #js #closure #examples
ADD COMMENT
Topic
Name
3+8 =