0

just a quick question on recursion. I'm trying to make a function that displays the integers in a a range. It prints all the integers but when it gets to the end it just shows undefined.

Here's the code.

function range(start, end) {
    var _start = start;
    if (_start < end) {
        console.log(_start);
        range(start + 1, end);
    } else {
        console.log(_start)
    }
}
rrk
  • 15,214
  • 4
  • 26
  • 42

1 Answers1

4

By default javascript functions return undefined unless you explicitly return something.

Bergi
  • 572,313
  • 128
  • 898
  • 1,281
AB Udhay
  • 633
  • 4
  • 9