I am trying to understand how the number variable is determined based on example from the book Eloquent Javascript.
When I output number I can see it growing as the loop progresses, but i can’t see where the number variable is actually set.
(Note: For anybody who understands Eloquent Javascript I have changed over the show() function to alert())
function forEach(array, action) {
for (var i = 0; i < array.length; i++)
action(array[i]);
}
function sum(numbers) {
var total = 0;
forEach(numbers, function (number) {
total += number;
});
return total;
}
alert(sum([1, 10, 100, 1000]));
In this part
numberis taken from the currentnumbers, and is equivalent to: