Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript closure

function makeAdder(x) {
  return function(y) {
    return x + y;
  };
}

var add5 = makeAdder(5);
var add10 = makeAdder(10);

console.log(add5(2));  // 7
console.log(add10(2)); // 12
Source by www.javascripttutorial.net #
 
PREVIOUS NEXT
Tagged: #javascript #closure
ADD COMMENT
Topic
Name
1+4 =