What's the difference between Spread operator and Rest operator?

The Spread operator and Rest paremeters have the same operator ... the difference between is that the Spread operator we give or spread individual data of an array to another data while the Rest parameters is used in a function or an array to get all the arguments or values and put them in an array or extract some pieces of them.

function add(a, b) {
  return a + b;

const nums = [5, 6];
const sum = add(...nums);

In this example, we're using the Spread Operator when we call the add function we are spreading the nums array. So the value of parameter a will be 5 and the value of b will be 6. So the sum will be 11.

function add(...rest) {
  return rest.reduce((total,current) => total + current);

console.log(add(1, 2)); // logs 3
console.log(add(1, 2, 3, 4, 5)); // logs 15

In this example, we have a function add that accepts any number of arguments and adds them all and return the total.

const [first, ...others] = [1, 2, 3, 4, 5];
console.log(first); //logs 1
console.log(others); //logs [2,3,4,5]

In this another example, we are using the Rest operator to extract all the remaining array values and put them in array others except the first item.