We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Rest Parameters

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.

Assignment

    • Return the string "No Labels" if there are no labels
    • Return the string "Label: LABEL" if there is only one label (where LABEL is the first label)
    • Return the string "Labels: LABEL, LABEL" if there are multiple labels (LABEL is each label separated by a comma and a space)