Javascript Function Closure Function Factory

Description

Javascript Function Closure Function Factory



// A function factory that multiplies numbers
function multiplyFactory(multiplier) {
    return function(amount) {
        return amount*multiplier;
    }//  w  w w .  j  av  a 2  s  .  com
}
let timesTen = multiplyFactory(10);
console.log( timesTen(4) ); // 40



PreviousNext

Related