"I understand that a and b are supposed to be elements in the array, but how on earth does JavaScript know which one is which?"
I don't understand any of these questions you were asking when first analyzing reduce. First a and b were not elements in an array, but rather parameters, that is how they are figured out which are which. The person asking those questions, don't understand the difference between functions and arrays.
Well, bis an element of the array in the sense that it represents the element currently being processed in the array. Even MDN speaks of it that way (and even a would be an element in the array for the first invocation of the callback function in that particular case.)
At any rate, I think the root of our misunderstanding is that you seem to be taking my words as talking about their syntactic function (so to speak), while I'm talking about the value they represent and how reduce() deals with them.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
"I understand that a and b are supposed to be elements in the array, but how on earth does JavaScript know which one is which?"
I don't understand any of these questions you were asking when first analyzing reduce. First a and b were not elements in an array, but rather parameters, that is how they are figured out which are which. The person asking those questions, don't understand the difference between functions and arrays.
Well,
b
is an element of the array in the sense that it represents the element currently being processed in the array. Even MDN speaks of it that way (and evena
would be an element in the array for the first invocation of the callback function in that particular case.)At any rate, I think the root of our misunderstanding is that you seem to be taking my words as talking about their syntactic function (so to speak), while I'm talking about the value they represent and how
reduce()
deals with them.