Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Default and Rest Parameters

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 111: The Spread Operator (...)

Implement `sumWithBase(base = 10, ...nums)` returning `base` plus the sum of the rest arguments.

Sample tests

Input: sumWithBase(5, 1, 2, 3)
Output: 11
Input: sumWithBase(, 1, 2)
Output: 13

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • The default base applies only when the argument is undefined.

Learning resources

  • MDN: Destructuring assignment
Visualize this concept: Spread and Rest →
Approach & explanation (try first)

A default parameter plus rest parameters lets base fall back to 10 while the remaining arguments are summed.

Loading...
⌘/Ctrl + Enter

Run your code to see results.