Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Difference Between the Spread and Rest Operators in JavaScript

// We use the spread operator to spread array values or iterables into maybe an array or object.

// While we use the Rest operator to gather the remaining elements passed into a function as an array.

const myFunction = (name1, ...rest) => { // used rest operator here
    console.log(name1);
    console.log(rest);
};

let names = ["John", "Jane", "John", "Joe", "Joel"];
myFunction(...names); // used spread operator here
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #Difference #Between #Spread #Rest #Operators #JavaScript
ADD COMMENT
Topic
Name
3+4 =