1. Spread Operator
_The spread operator (…) _is used to spread the contents of an array or object into individual elements. This is useful when you want to combine multiple arrays or objects into a single array or object, Or when passing arrays or objects as arguments.
In the example below, we use the spread operator to add the element
0 to the beginning of the
The spread operator can also be used with objects.
2. Rest Operator
The rest operator (…) is used to represent an indefinite number of arguments as an array. This is useful when you want to pass a variable number of arguments to a function, or when you want to group a set of arguments into an array.
In this example, we define a function called
sum that uses the rest operator to collect any number of arguments into an array called
numbers. We then use the
reduce method to sum up the numbers in the array and return the result.
Thanks for reading 🙌