Lesson 21 of 55
javascriptSpread & Rest Syntax
7 mins
Course progress38%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 21 of 55
javascript7 mins
Keep these ideas in mind as you work through the lesson.
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}