Question about "Return Largest Numbers in Arrays"

I just completed “Return Largest Numbers in Arrays”, and I don’t understand why var bigArray=0; has to be within the inner loop to work:

With the variable on the very outside, this function doesn’t work for the second array:

But with the variable within the inner loop, it works:

On this problem’s Wiki, it says the var must be within the inner loop “so it won’t be reassigned until we find a larger number.” But I’m not sure why it matters. Can anyone explain?

Thank you!

You need to reset bigArray between loops. If bigArray is not reset it will be 27 when you’ll start to iterate over the second array and as no value in the second array is bigger than 27 you’ll assign 27 to results[1].