View
Rest syntax는 마지막 변수 이후의 array 의 나머지 모든 elements를 모은다.
skip된 elements를 포함하지 않는다.
const mainMenu = ["Pizza", "Pasta", "Risotto"];
const starterMenu = ["Focaccia", "Bruschetta", "Garlic Bread", "Caprese Salad"];
const [pizza, , risotto, ...others] = [...mainMenu, ...starterMenu];
pizza // "Pizza"
risotto // "Risotto"
others // ["Focaccia", "Bruschetta", "Garlic Bread", "Caprese Salad"]
따라서 Rest element는 반드시 마지막 element로 작성되어야 한다.
const [pizza, , risotto, ...others, bread] 이런식으로 작성할 수 없다.
rest syntax와 spread syntax는 같은 생김새지만 반대로 사용된다.
사용된 곳에 따라서 다르게 사용된다.
spread syntax는 values를 넣을 곳에 ","로 구분되는 곳에 사용
rest syntax는 variable 이름을 작성할 곳에 ","로 구분되는 곳에 사용
reply