Create closures - Javascript Function

Javascript examples for Function:Closure

Description

Create closures

Demo Code

function retirement(retirementAge) {
  var a = ' years left until the retirement';
  return function(yearOfBirth) {
    var age = 2017 - yearOfBirth;
    console.log((retirementAge - age) + a);
  }/*w w  w.  j  a v a 2 s .  co m*/
}

var retirementUS = retirement(66); //=>  it returns a function
var retirementGermany = retirement(65);
var retirementIceland = retirement(67);

retirementUS(1990); 
retirementGermany(1996);
retirementIceland(1986);

Related Tutorials