Nesting For Loops... does var product always = 0?

I passed the “Nesting For Loops” block on freecodecamp and I was wondering why we need the line

 product = product * arr[i][j];

in our code if we declared that var product was equal to one at the outset of the code? Since product=1 and 1 multiplied by anything is itself, we should be able to write

product = arr[i][j];

I tried that line of code and it did not work which told me that var product changes in value as the loop runs. Can someone tell me what in the code makes the var product change?

Thanks!

The line you quote

product = product * arr[i][j];

is what changes the value of product.

On the right side it takes the current value of ‘product’ and multiplies it by arr[i][j].

Then it assigns that value back to ‘product’, updating (mutating) it’s value.

So, product is only equal to 1 to begin with and each time your program goes through the loop, it will change.

Thanks… I should have made that connection.