Skip to content

Files

Latest commit

40d1f80 · May 30, 2019

History

History
14 lines (10 loc) · 498 Bytes

rest-parameters.md

File metadata and controls

14 lines (10 loc) · 498 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.