Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript closure

function numberGenerator() {
  // Local “free” variable that ends up within the closure
  var num = 1;
  function checkNumber() { 
    console.log(num);
  }
  num++;
  return checkNumber;
}

var number = numberGenerator();
number(); // 2
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #javascript #closure
ADD COMMENT
Topic
Name
3+6 =