cf.completefrontend

Predict the outputMedium

What does reduce do here when you don't pass an initial value?

What does this log?
const calls = [];
const sum = [1, 2, 3].reduce((acc, n, i) => {
  calls.push(i);
  return acc + n;
});
console.log(sum, calls);
 
console.log([5].reduce(() => "never called"));
console.log([].reduce((acc, n) => acc + n));
console.log("done");

The answer

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

Checking your sign-in…