Spread Operator & Rest Operator Javascript
- The spread operator, represented by three dots(
...), expands an iteratable object (like an array, string, or object literal) into its individual elements
function multiply(num1, nums2) {
console.log(num1 * num2);
}
var arr = [5, 6];
multiply(...arr); // spread operator
- The Rest Operator, represented by three dots (
...), allows a function to accept an indefinite number of arguments as an array.
function multiply(...nums) { // Rest Operator
console.log(nums[0] * nums[1]);
}
var arr = [5, 6];
multiply(...arr); // Spread Operator