

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Arrays
incomplete
2: Type Parameters
incomplete
3: Heterogeneous Arrays
incomplete
4: Rest Parameters
incomplete
5: Evolving Any
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Rest parameters allow an indefinite number of final arguments, and brings them into the function body as an array. They're denoted by three dots (...) before the parameter name.
function gatherParty(partyName: string, ...adventurers: string[]): string {
return `${partyName} consists of: ${adventurers.join(", ")}`;
}
const msg = gatherParty("The Fellowship", "Frodo", "Sam", "Gandalf");
console.log(msg);
// "The Fellowship consists of: Frodo, Sam, Gandalf"
Don't confuse rest parameters with the similar but different spread syntax.
You've used rest parameters before, maybe without even realizing! console.log accepts rest parameters.
"No Labels" if there are no labels"Label: LABEL" if there is only one label (where LABEL is the first label)"Labels: LABEL, LABEL" if there are multiple labels (LABEL is each label separated by a comma and a space)