# 1.1.2命名与环境

> 译者： [https://sicp.comp.nus.edu.sg/chapters/4](https://sicp.comp.nus.edu.sg/chapters/4)

<split>编程语言的一个关键方面是它提供使用名称来引用计算对象的方式，而我们的第一个此类方式是_常量_。 我们说该名称标识一个常量，其_值_是对象。

在JavaScript中，我们使用_常量声明_来命名常量。 打字

```js
const size = 2;
```

causes the interpreter to associate the value 2 with the name `size`. The purpose of the constant declaration is to create this association, and not to compute a particular value as for expression statements. The JavaScript specification demands that the special value `undefined` shall be the result of evaluating such constant declarations.

将名称`size`与数字2关联后，我们可以通过名称来引用值2，如下所示：

```js
size;
```

or

```js
5 * size;
```</split>  <split>&lt;edit&gt;当然，在可以在表达式中使用名称`size`之前，JavaScript解释器需要为`size`执行常量声明。 为简便起见，在此在线书中，省略了在评估新语句之前需要评估的语句。 但是，为了观看和玩该程序，可以单击它。 该程序以所有必需的语句开头，然后出现在新的浏览器选项卡中。 因此，单击&lt;/edit&gt;

```js
5 * size;
```

后，将出现一个新标签，其中包含以下语句：

```js
const size = 2;
5 * size;
```

JavaScript语句可以按顺序放置。 解释器按给定顺序评估序列的组成部分，并将最后一个组成部分的值视为序列的值。</split> <split>以下是`const`的其他使用示例：

```js
const pi = 3.14159;
```

```js
const radius = 10;
```

```js
pi * radius * radius;
```

```js
const circumference = 2 * pi * radius;
```

```js
circumference;
```

Constant declaration is our language's simplest means of abstraction, for it allow us to use simple names to refer to the results of compound operations, such as the `circumference` computed above. In general, computational objects may have very complex structures, and it would be extremely inconvenient to have to remember and repeat their details each time we want to use them. Indeed, complex programs are constructed by building, step by step, computational objects of increasing complexity. Our interpreter facilitates this step-by-step program construction because name-object associations can be created incrementally in successive interactions.</split>

应该清楚的是，将值与名称相关联并在以后检索它们的可能性意味着解释器必须维护某种内存来跟踪名称-对象对。 该内存称为_环境_（更确切地说是_全局环境_，因为稍后我们将看到计算可能涉及许多不同的环境）。 [[1]](4#footnote-1)

* * *

[[1]](4#footnote-link-1) Chapter 3 will show that this notion of environment is crucial, both for understanding how the interpreter works and for implementing interpreters.

