المعرفة:: JavaScript الحالة::مؤرشفة المراجع:: syahshiimi’s notes, The Complete JavaScript Course 2022 From Zero to Expert
What is the Rest Pattern?
- It works exactly the same as the spread operator… working with the
...
but does the opposite of thespread
operator. - In short, it is to pack elements into an array, opposite to the spread (unpack elements from an array).
- The Rest operator works on the left hand side of the operator i.e. -spread` operator.
- Rest must be the last element.
- In object destructuring process, the rest operator creates an object.
- It can be used in functions as well.
Summary
The rest pattern is used in places which we would otherwise write variables names separated by commas. This is because the rest operator collects these variable names and packs them into either an object or an array.