> For the complete documentation index, see [llms.txt](https://yes-1-am.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yes-1-am.gitbook.io/blog/typescript-yu-fa/mei-ju.md).

# 枚举

如 第一章基础类型所讲：

```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` 修饰符来定义。

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