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.
1 2 3 4 5 6 |
function mynumbers(nums) { console.log(nums) } mynumbers(7,8,9) |
Even tough you can use arguments for print different parameters.
1 2 3 4 5 6 |
function mynumbers(nums) { console.log(arguments) } mynumbers(7,8,9) |
But in JavaScript ES6 we have another operator to do this, you can use REST Operator for performing of these kind functionalities.
1 2 3 4 5 6 |
function mynumbers(...nums) { console.log(nums) } mynumbers(7,8,9) |
Exercise Files
No Attachment Found