I am working on understanding recursion. I wrote a function that returns the sum of an array.
If the if statement for the base case looks like this if (arr.length === 0), the function works. If it looks like this if (arr === []), I get a stack overflow. Why is that? Here is the full program.
const getSum = function (arr){
//the if statement in question
if (arr.length === 0){
return 0;
}
else{
console.log(arr)
return arr[0] + getSum(arr.slice(1));
};
};