Rest Parameters (...)

JavaScript Rest Parameters ..., i.e three full stops are used in functions using resp operator (...). Its is used as last parameter of function only. The rest operator prefix replace all parameters to JS Arrays.

The Rest Parameter is different from spread operator, although they look same. The Rest Operator (...) extracts Arrays and is used for Rest Parameters and Destructuring.

Resp Parameters Example


    function toArray(...args){
        return args;
    console.log( toArray(1,2,3) );

Rest Operator (...)

Rest parameters are used using rest operator (...). The triple dot or full stop is actually resp operator. Its is used as prefix to functions last parameter.

Earlier we use arguments keyword, but

Check Parameters count using resp operator


    function checkLength(...x){ 
        let count=0;
        for( let i in x){
        return count;

Check Arguments Length


    function checkLength(...x){ 
        return x.length;