Closed Bug 1246421 Opened 9 years ago Closed 9 years ago

example in the comma operator section

Categories

(Developer Documentation Graveyard :: JavaScript, defect, P5)

All
Other
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: gaetanoortisi, Unassigned)

References

()

Details

:: Developer Documentation Request Request Type: Correction Gecko Version: unspecified Technical Contact: :: Details I think the example provided is wrong. I tested it and it does not scan the entire diagonal of the array. I post it here: -- For example, if a is a 2-dimensional array with 10 elements on a side, the following code uses the comma operator to update two variables at once. The code prints the values of the diagonal elements in the array: for (var i = 0, j = 9; i <= j; i++, j--) console.log("a[" + i + "][" + j + "]= " + a[i][j]); -- It scans only the following elements: a[0][9], a[1][8], a[2][7], a[3][6], a[4][5]. Changing the exit condition to j >= 0 solves it. Bye, tano
Thanks for spotting it :) I've fixed it. It had been fixed there https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator#Examples but not in the doc you linked.
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.