# 함수 파라미터에서의 rest(params)

## Rest 파라미터

**Rest 파라미터** 구문은 정해지지 않은 수(an indefinite number, 부정수) 인수를 배열로 나타낼 수 있게 합니다.

```javascript
function sum (a,b,c,d,e,f,g) {
  return a+b+c+d+e+f+g
}
console.log(sum(1,2,3,4,5,6,7))
```

이런 상황에서 결과는&#x20;

```javascript
//결과)
28
```

만약에 함수를 사용하는 쪽에서 인자를 한개라도 없다

```javascript
console.log(sum(1,2,3,4,5,6,))
```

결과는 아래와 같다.

```javascript
//결과)
NAN 
```

이것을 해결하기 위해서는\
함수 파라미터에서에 값을 **Rest**(배열형태)로 받는것 입니다.\
\&#xNAN;**'이 자리에 오는 모든 파라미터를 \[ ] 중괄호로 감싸준 파라미터”** 라는 뜻입니다.&#x20;

```javascript
function sum(...params) {  //Rest
  console.log(params);
  return params.reduce((acc, current) => acc + current, 0);
}
console.log(sum(1, 2, 3, 4, 5, 6));
```

```javascript
//결과)
[1, 2, 3, 4, 5, 6]
21
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://triplexlab.gitbook.io/vanilla-js/02.vanilla-js/07-spread-rest/rest-params.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
