I created on recursion program to find of sum of all values till the number via recursion(with return values). Then I thought of making same program by passing the total as argument. this one didnt work. When I tried debugging i found that last else(when n==1) takes the porgram to loader.js. I am new and couldn't understand what is happening here. Looking for your expert feedback.
function sum(n, total = 0) {
console.log(n, total);
if (n !== 1) {
console.log("insie IF");
total += n;
sum(n - 1, total);
} else {
console.log("inside ELSE");
total += 1;
}
return total;
}