spread-operator
allows an iterable such as an array or string to be expanded in places where zero or more arguments are expected
(unpacks the elements)
allows an iterable such as an array or string to be expanded in places where zero or more arguments are expected
(unpacks the elements)
maximum return NaN because it is contained in an array
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let maximum = Math.max(numbers);
console.log(maximum); // NaN
spread operator unpacks array elements into individual arguments,
so it can be used with Math.max()
maximum returns 9 because 9 is the biggest element in array
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let maximum = Math.max(...numbers);
console.log(maximum);
by using the spread operator (...) it is possible to extract items from itemSet2 and add them to itemSet1 in one line of code
let itemSet1 = ["apple", "orange", "banana", "mango", "lemon"];
let itemSet2 = ["tomato", "potato", "onion"];
itemSet1.push(...itemSet2);
console.log(itemSet1); //(8) 0: "apple 1: "orange" 2: "banana" 3: "mango" 4: "lemon" 5: "tomato" 6: "potato" 7: "onion"
console.log(...itemSet1); // apple orange banana mango lemon tomato potato onion