Recursive Function: Looking For Better Explanation

please someone explane this recursive loop to me, i understand the process until reached base case then it gets complicated… number parameter starts assending and return statement doesn’t make sense to me anymore.
Capture d’écran 2024-02-03 102648

const countDownAndUp = (number) => {
  console.log(number);

  if (number === 0) {
    console.log("Reached base case");
    return;
  } else {
    countDownAndUp(number - 1);
    console.log(number);
  }
};

countDownAndUp(3);

Capture d’écran 2024-02-03 102720

after the function call there is a console.log, so once the function has finished running, the next thing is the number being logged to the console.
You could try running through the code using this tool: Online JavaScript Compiler, Visual Debugger, and AI Tutor - Learn JavaScript programming by visualizing code

1 Like

thank you, that’s a really helpful tool