So im brand new to learning javascript and although i have a basic idea of what var is, i would like to know why has var been used in the following code the second time when we are calling the function multiplyAll. I tested this function and the console shows the same answer when i dont use the var product and just call the multiply function with the nested array as arguments
function multiplyAll(arr) {
var product = 1;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
product *= arr[i][j];
}
}
return product;
}
var product = multiplyAll([
[1, 2],
[3, 4],
[5, 6, 7]
]);
console.log(product);