I am confused about the spread syntax and rest parameter in ES2015. Can anybody explain the difference between them with proper examples?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
When using spread, you are expanding a single variable into more:
When using rest arguments, you are collapsing all remaining arguments of a function into one array:
Javascript's three dots (
...
) operator can be used in two different ways:Note that the spread operator can be the first element, but the rest parameter needs to be the last to collect the rest elements .