TypeScript · Junior · Question 50 of 75
How do you specify that a function accepts any number of numbers?
- ✓Correct answer:
function sum(...nums: number[]) - 2
function sum(nums...: number) - 3
function sum(*nums: number)
Explanation
A rest parameter collects the arguments into an array; its type is an array or a tuple. Call it as sum(1, 2, 3) or sum(...arr).