Instructions
- 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
- 2. Thoroughly review each solution before proceeding to ensure full understanding.
- 3. Final results will be available after submission to provide insights into areas for further improvement.
- 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
- 5. Once submitted, responses are final, so ensure you’re confident in your answers.
- 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.
All Problems
Question
Action
What is a recursive function?
Which of the following is required for a recursive function to avoid infinite recursion?
What will the following code output? function countdown(n) { if (n === 0) return; console.log(n); countdown(n - 1); } countdown(3);
How can you define a recursive function in JavaScript?
What will be the output of this code? function sum(n) { if (n === 0) return 0; return n + sum(n - 1); } console.log(sum(5));
What is a potential risk when writing recursive functions?
What will the following code output? function factorial(n) { if (n === 1) return 1; return n * factorial(n - 1); } console.log(factorial(4));
Which of the following is true about recursion?
What will be the output of this code? function fib(n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } console.log(fib(5));
What is one common use case for recursive functions in JavaScript?