cf.completefrontend

Predict the outputMedium

In what order does this recursive countdown log?

What does this log?
function countdown(n) {
  if (n === 0) {
    console.log("liftoff");
    return;
  }
  console.log("before", n);
  countdown(n - 1);
  console.log("after", n);
}
 
countdown(3);

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…