Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Sum All Arguments

A Closer Look at Functionseasy

Course · Section 10: A Closer Look at Functions · Lecture 135: Default Parameters

Implement `sumArgs(...nums)` returning the sum of all arguments passed, using rest parameters.

Sample tests

Input: sumArgs(1, 2, 3)
Output: 6
Input: sumArgs()
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Using the arguments object instead of rest params loses array methods.

Learning resources

  • MDN: Functions
Visualize this concept: The Scope Chain →
Approach & explanation (try first)

...nums gathers every argument into a real array, which reduce then sums.

Loading...
⌘/Ctrl + Enter

Run your code to see results.