When the names of arguments in a function call match the names of the function parameters, it contributes to clearer, more readable code. However,
when the names match, but are passed in a different order than the function parameters, it indicates a mistake in the parameter order which will
likely lead to unexpected results.
Noncompliant Code Example
function divide(divisor, dividend) {
return divisor/dividend;
}
function doTheThing() {
var divisor = 15;
var dividend = 5;
var result = divide(dividend, divisor); // Noncompliant; operation succeeds, but result is unexpected
//...
}
Compliant Solution
function divide(divisor, dividend) {
return divisor/dividend;
}
function doTheThing() {
var divisor = 15;
var dividend = 5;
var result = divide(divisor, dividend);
//...
}
Exceptions
Swapped arguments that are compared beforehand in an enclosing if
-statement are ignored:
function divide(divisor, dividend) {
return divisor/dividend;
}
function doTheThing() {
var divisor = 15;
var dividend = 5;
if (divisor > dividend) {
var result = divide(dividend, divisor);
//...
}
}