> For the complete documentation index, see [llms.txt](https://yamoo9.gitbook.io/typescript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yamoo9.gitbook.io/typescript/ts-vs-es6/spread-default-reset.md).

# 전개 연산자 / 매개변수

## Default Parameters

ES6부터 **함수 매개 변수의 기본 값을 설정**할 수 있습니다. TypeScript는 매개 변수 타입 설정 후 `=` 뒤에 기본 값을 할당하면 됩니다. 컴파일 된 코드를 살펴보면 기본 값으로 할당된 매개 변수는 `void 0`과 비교한 후 조건이 참일 경우 기본 값을 설정합니다. ( `void 0`은 `undefined`와 동일합니다)

**작성 코드:**

{% code title="TypeScript" %}

```typescript
function countDown(start:number = 10): ()=>number {
  return () => start > 0 ? start-- : 0;
}
```

{% endcode %}

**컴파일 코드:**

{% code title="JavaScript" %}

```javascript
function countDown(start) {
  if (start === void 0) { start = 10; }
  return function () { return start > 0 ? start-- : 0; };
}
```

{% endcode %}

## Spread Operator

ES6부터 **전개 연산자를 사용**할 수 있습니다. 전개 연산자는 쓰임새가 다양합니다. TypeScript 역시 전개 연산자를 훌륭하게 지원합니다. 활용 방법을 살펴봅시다.

**작성 코드:**

{% code title="TypeScript" %}

```typescript
let numbers:number[] = [101, 21, -12, 934, 87];

// 배열 내부 아이템으로 결합
numbers = [10, 31, 11, ...numbers, -2, 0];

// 배열 ⟹ 개별 아이템으로 순차적 제공
let min_number:number = Math.min(...numbers);
let max_number:number = Math.max(...numbers);
```

{% endcode %}

**컴파일 코드:**

{% code title="JavaScript" %}

```javascript
var numbers = [101, 21, -12, 934, 87];

numbers = [10, 31, 11].concat(numbers, [-2, 0]);

var min_number = Math.min.apply(Math, numbers);
var max_number = Math.max.apply(Math, numbers);
```

{% endcode %}

## Rest Parameters

ES6부터 **나머지 매개 변수를 사용**할 수 있습니다. 나머지 매개 변수는 함수에서 활용되며 전개 연산자를 매개변수 앞에 붙여 사용합니다. TypeScript에서 활용 방법 또한 동일합니다.

**작성 코드:**

{% code title="TypeScript" %}

```typescript
function makeArray(...args:(number|string)[]): (number|string)[] {
  return args;
}

makeArray(11, 'eleven', 100, 'one hundred');
```

{% endcode %}

**컴파일 코드:**

{% code title="JavaScript" %}

```javascript
function makeArray() {
  var args = [];
  for (var _i = 0; _i < arguments.length; _i++) {
    args[_i] = arguments[_i];
  }
  return args;
}

makeArray(11, 'eleven', 100, 'one hundred');
```

{% endcode %}

{% embed url="<https://slides.com/yamoo9/es6#/1>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://yamoo9.gitbook.io/typescript/ts-vs-es6/spread-default-reset.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
