Skip to content

JavaScript Rest Parameters

When declaring the parameters of a function, the three-point and a parameter declared with a name give all the parameter values ​​as an array, except the parameters that were previously reported to the function. These are called rest (all other parameters) parameters.

function exam(...param) {
        exam(1, 2);

output: 1 , 2 , 5              

function multiplication(withWhat, ...numbers) {
            var res = 0;
            for (var i = 0; i < numbers.length; i++) {
                res += numbers[i] * withWhat;}
            return res;

output: 30


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: