Skip to main content

Command Palette

Search for a command to run...

How to use rest operator/ Parameter in javascript

Updated
1 min read
How to use rest operator/ Parameter in javascript
A

I am working as freelancer. I am a experienced full stack web developer. My lovely stack is MERN but I am open for new tech. I love to work with teammates for achieve goals. I love researches to find specific new things.

What is the rest parameter?

It is just the opposite of a spread operator. It bounds spreading values into the elements of an array. It gives access to a function to use an indefinite number of arguments as an array. It is denoted by '...' symbol.

syntax

function f(a, b, ...myarg){

//..

}

A function definition can only have one rest parameter and the rest parameter must be the last parameter.

Examples

Let's make a function of various parameters with the rest parameter.