> 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/block-scope.md).

# 블록 영역 변수, 상수 선언

ES6부터 **`let`, `const` 키워드를 사용해 변수, 상수를 정의**할 수 있습니다. TypeScript 또한 마찬가지로 활용 가능합니다. `let` 변수는 `var` 변수가 불러오는 문제점(중복 선언, 호이스트에 따른 의도치 않은 동작 등)을 훌륭하게 해결 하므로 사용이 권장됩니다. 그리고 `let`, `const` 키워드를 사용하면 블록 스코프(Block Scope)를 사용할 수 있습니다.

**작성 코드:**

{% code title="TypeScript" %}

```typescript
let context = document.querySelector('html');

{
  let context = document.querySelector('body');
  console.log('블록문 내부 context = ', context);
}

console.log('글로벌 context = ', context);
```

{% endcode %}

**컴파일 코드:**

{% code title="JavaScript" %}

```javascript
var context = document.querySelector('html');

{
  var context_1 = document.querySelector('body');
  console.log('블록문 내부 context = ', context_1);
}

console.log('글로벌 context = ', context);
```

{% 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/block-scope.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.
