(Apologies for any language barriers!) It's difficult to articulate my thoughts in English, but here is the code I've written:
function calculateAge(yearBorn){
return 2020 - yearBorn;
}
var johnAge = calculateAge(1990);
var janeAge = calculateAge(2000);
var stevenAge = calculateAge(1998);
console.log(johnAge, janeAge, stevenAge);
function yearsUntilRetirement(currentAge, name){
var age = calculateAge(currentAge);
var retirementYear = 65 - age;
console.log(name + ' retires in ' + retiredYear + ' years ');
}
yearsUntilRetirement(2000, "Alex");
This code functions perfectly fine and I'm curious as to why!
I have a function that calculates age (function calculateAge(yearBorn)
) and I utilize it within another function called yearsUntilRetirement
In the first function, there's only one parameter defined as yearBorn
, yet in the subsequent usage of the same function, a different parameter name calculateAge(currentAge)
is employed instead of calculateAge(yearBorn)
. Surprisingly, it still works!
What exactly is happening here?
Can differing parameter names be used even if the function remains the same?