I'm trying to be all cool and modern and use arrow function es6 js but failed at the first attempt.
Why does this arrow function sumRange NOT work:
var output = sumRange(3);
console.log(output);
sumRange = (num) => {
if(num == 1) return 1;
console.log(num);
return num + sumRange(num - 1);
}
But here the function DOES work:
var output = sumRange(3);
console.log(output);
function sumRange(num){
if(num == 1) return 1;
console.log(num)
return num + sumRange(num - 1);
}