Recursion test


1. What is the base case in recursion?




What is the result of the function call: factorial(3)?

function factorial(n) { return n === 0 ? 1 : n * factorial(n - 1); }




3. Which of the following problems can be solved using recursion?




4. What is infinite recursion?




5. What if a recursive function has no base case?




6. What is the result of the function call: fib(4)?
function fib(n) { return n <= 1 ? n : fib(n - 1) + fib(n - 2); }




7. What does the following recursive function do?

function countdown(n) { if (n <= 0) { console.log("Done"); }
                        else { console.log(n); countdown(n - 1); } }




8. Which of the following statements is true about recursion?




9. What is the result of the function call: sum(5)?

function sum(n) { return n === 0 ? 0 : n + sum(n - 1); }