Modern JavaScript
About Lesson

In this JavaScript lesson we are going to talk about JavaScript REST Operator, so It is used to handle function parameters, you can use three dot (…) for this. Rest operator signify that parameter is a placeholder for any number of arguments. and rest operator is used for handling function parameters. the best thing is this that the rest parameter is of Array type.

 

 

For example we have a function, in this function we have added a parameter, now when we call our function we can just add one parameter and it will print just one parameter.

 

 

Even tough you can use arguments for print different parameters.

 

 

 

But in JavaScript ES6 we have another operator to do this, you can use REST Operator for performing of these kind functionalities.

 

 

JavaScript REST Operator Features

We already have talked that REST operator in JavaScript is represented by three dots (…) and it is used to gather the remaining arguments of a function or the remaining elements of an array. these are some features of REST operator in JavaScript:

 

  1. Gathering Function Arguments: The REST operator can be used to gather the remaining arguments of function into an array. this is useful when function takes a variable number of arguments.

 

 

  1. Destructuring an Array: REST operator can be used to gather the remaining elements of an array into new array.

 

 

  1. Combining Arrays: REST operator can be used to combine two or more arrays into single array.

 

 

  1. Ignoring Function Arguments: REST operator can be used to ignore some of the arguments passed to function.

 

In result we can say that REST operator in JavaScript provides lot of flexibility and can help simplify code in many situations.