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,677
  • 4
  • 29
  • 45

1 Answers1

4

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

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
AB Udhay
  • 643
  • 4
  • 9