# 枚举

如 第一章基础类型所讲：

```javascript
enum Enum {
    A = 1,
    B = 2
}

会被编译为  

var Enum;
(function (Enum) {
    Enum[Enum["A"] = 1] = "A";
    Enum[Enum["B"] = 2] = "B";
})(Enum || (Enum = {}));
```

因此会产生多余的代码，因此可以采用 `const` 枚举，即常量枚举，常量枚举通过 `const` 修饰符来定义。

**常量枚举**不同于**常规的枚举**，常量枚举的代码会在编译阶段被删除。


---

# 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://yes-1-am.gitbook.io/blog/typescript-yu-fa/mei-ju.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.
