34 lines
833 B
Plaintext
34 lines
833 B
Plaintext
![]() |
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);
|
||
|
//...
|
||
|
}
|
||
|
----
|