Skip to content

Latest commit

History

History
12 lines (10 loc) 路 488 Bytes

rest-parameters.md

File metadata and controls

12 lines (10 loc) 路 488 Bytes

Rest Parameters

Rest parameters (denoted by ...argumentName for the last argument) allow you to quickly accept multiple arguments in your function and get them as an array. This is demonstrated in the below example.

function iTakeItAll(first, second, ...allOthers) {
    console.log(allOthers);
}
iTakeItAll('foo', 'bar'); // []
iTakeItAll('foo', 'bar', 'bas', 'qux'); // ['bas','qux']

Rest parameters can be used in any function be it function/()=>/class member.