Lesson 21 of 55 · javascript
Spread & Rest Syntax
Duration: 7 mins
Spread expands an iterable into individual elements.
const a = [1,2];
const b = [...a,3,4]; // [1,2,3,4]
Rest gathers remaining elements into an array.
function sum(...nums){ return nums.reduce((a,b)=>a+b,0); }
Works with objects as well.
const obj1 = {a:1};
const obj2 = {...obj1, b:2}; // {a:1,b:2}