I have one simple recursive function which adds all it's previous numbers.
function add(n) {
if (n == 0) {
return 1; // when it reaches here it should give me 1.
}
return n + add(n - 1);
}
console.log( add(5) ); // give me 16
when the execution reaches line number 3, it should return me 1, but it is return me 16. how return is actually working here ?