HardClosures & Scope💻 Output Question

Function is called with arguments object

💡

Hint

arguments is only available in regular functions. Rest params (...args) work everywhere and are the modern replacement.

What does this output?

function sum() {
  return Array.from(arguments).reduce((a, b) => a + b, 0);
}
const sumRest = (...args) => args.reduce((a, b) => a + b, 0);
console.log(sum(1, 2, 3, 4));
console.log(sumRest(1, 2, 3, 4));

Correct Output

10
10

Why this output?

Explanation: arguments is available in regular functions (not arrows). Rest params (...args) work in both and are more explicit. Both produce the same sum.

Key Insight: arguments is only available in regular functions. Rest params (...args) work everywhere and are the modern replacement.

More Closures & Scope Output Questions

EasyClassic var in loop with setTimeoutEasylet in loop — each iteration gets own bindingMediumIIFE captures loop variableMediumClosure mutation persists across calls

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz