Hi everyone, I'm in the process of learning Javascript and I'm confused about having a function inside another function, in particular the argument part.
I've included a sample code from the lesson where it's looking to calculate the years until retirement for three people given their year of birth.
What I'm confused about is the year within the function yearUntilRetirement(name, year).
Shouldn't this be yearOfBirth instead of year since it's looking back at the calculateAge(yearOfBirth) function to find the age? Or is this argument only unique to the function it is currently in?
function calculateAge(yearOfBirth) {
var age = 2016 - yearOfBirth;
return age;
}
function yearsUntilRetirement(name, year) {
var age = calculateAge(year);
var retirement = 65 - age;
console.log(name + ' retires in ' + retirement + ' years.');
}
yearsUntilRetirement('John', 1990);
yearsUntilRetirement('Mike', 1969);
yearsUntilRetirement('Mary', 1948);
yearis within the scope of thecalculateAgeinterpreted asyearOfBirth. Naming variables consitently improves understanding.