Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How Do Rest Parameters Work in JavaScript?

// With rest parameters, you can define a function to store multiple arguments in a single array

function sayHello(message, ...names){
  names.forEach(name => console.log(`${message} ${name}`));
}

sayHello('Hello', "John", "Smith", "Doe");

/*
output:

Hello John

Hello Smith

Hello Doe 

*/

// The ... is what makes names a rest parameter.
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #How #Do #Rest #Parameters #Work
ADD COMMENT
Topic
Name
5+4 =