# 나머지 매개변수 (Rest parameter)

C언어에서 가변인자와 같은 기능이다. 문법은 다음과 같다.

```javascript
function f(...args) {
  // ...
}
```

이것 역시 ES6 부터 추가되었으며, 사용을 권장하고 있다.

이전에도 `arguments` 라는 예약어가 있었으나, 이건 파라미터 전부에 접근한다. (쉘에서 `$1` 의 표현을 떠올리면 이해하기 쉽다.)

그럼 얘는 뭐가 다르냐?

`arguments`는 따로 정의된 특수한 객체지만, 나머지 매개변수는 `Array`의 인스턴스이다.

그리고 `...<name>` 에 해당하는 부분만 `Array`로 넘어간다.

```javascript
function f(tag, ...msg) {
   return tag +": " + msg.join('/');
}

f('alphabet', 'a', 'b', 'c');  // "alphabet: a/b/c"
f('primes', 2, 7, 9, 11);      // "primes: 2/7/9/11"
```

그렇다보니 `...arr` 로 넘기고 `arr.pop()` 과 같은 조작이 가능하다.

## Links

* <https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Functions/rest_parameters>


---

# 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://devlog.joonas.io/javascript/rest-parameter.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.
