# 1.1.1表达式

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

<split>开始使用JavaScript编程的一种简单方法是与您用于查看此页面的浏览器中内置的JavaScript解释器进行交互。 JavaScript程序称为_语句_。 我们将显示的语句设置为深色背景，以便您可以单击它们。 鼠标单击JavaScript语句的方式设置为显示JavaScript解释器，该解释器可以_评估_语句并显示结果值。 顺便说一下，使鼠标单击JavaScript语句以显示解释器的程序本身就是用JavaScript编写的； 我们将其称为_脚本_用于鼠标单击。</split>  <split>一种语句是表达式语句，它由_表达式_组成，后跟分号。 一种简单的表达式是数字。 （更确切地说，表达式由表示以10为底的数字的数字组成。）如果您要求我们的脚本显示表达式语句的解释器，

```js
486;
```

by clicking it, it will respond by creating a separate browser tab where the statement is shown, with the option to evaluate the statement. Click on the primitive expression statement, and see what happens!</split> <split>表示数字的表达式可以与运算符（例如`+`或`*`）组合以形成一个复合表达式，该表达式表示将相应的原始函数应用于这些数字。 例如，通过单击以下表达式来评估以下任何表达式 [[1]](3#footnote-1) ：

```js
137 + 349;
```

```js
1000 - 334;
```

```js
5 * 99;
```

```js
10 / 5;
```

```js
2.7 + 10;
```</split>  <split>诸如此类包含其他表达式作为组成部分的表达式称为_组合_。 由中间的_运算符_符号以及其左侧和右侧的_操作数_表达式形成的组合称为_运算符组合_。 通过将运算符指定的函数应用于作为操作数的值的_自变量_，可以获得运算符组合的值。</split>  <split>将运算符放在操作数之间的惯例称为_前缀表示法_。 它遵循数学符号，即读者最有可能在学校和日常生活中熟悉。 与数学中一样，运算符组合可以_嵌套_嵌套，也就是说，它们可以采用本身就是运算符组合的参数：

```js
(3 * 5) + (10 - 6);
```

As usual, parentheses are used to group operator combinations in order to avoid ambiguities. JavaScript also follows the usual conventions when parentheses are omitted; multiplication and division bind stronger than addition and subtraction. For example,

```js
3 * 5 + 10 / 2;
```

stands for

```js
(3 * 5) + (10 / 2);
```

We say that `*` and `/` have _higher precedence_ than `+` and `-`. Sequences of additions and subtractions are read from left to right, as are sequences of multiplications and divisions. Thus,

```js
3 / 5 * 2 - 4 + 3;
```

stands for

```js
(((3 / 5) * 2) - 4) + 3;
```

We say that the operators `+`, `-`, `*` and `/` are left-associative.</split> <split>此类嵌套的深度和JavaScript解释器可以评估的表达式的整体复杂性（原则上）没有限制。 是我们人类可能会被诸如此类的相对简单的表达所迷惑

```js
3 * 2 * (4 + (3 - 5)) + 10 * (27 / 6);
```

which the interpreter would readily evaluate to be 57\. We can help ourselves by writing such an expression in the form

```js
3 * 2 * (4 + (3 - 5)) 
+ 
10 * (27 / 6);
```

to visually separate the major components of the expression.</split> <split>解释器始终以相同的基本周期运行：它从浏览器读取一条语句，评估该语句，然后打印结果。 通常通过说解释器在 _read-eval-print循环_中运行来表示这种操作模式。 特别要注意的是，没有必要明确地指示解释器打印语句的值。</split> 

* * *

[[1]](3#footnote-link-1) Note that the semicolon indicates to the JavaScript interpreter that the expression should be taken as a statement, and thus as a complete program. However, JavaScript systems are not strict about these semicolons; they can often be left out. In this book, we will never leave out these optional semicolons, and point out which statements come with semicolons and which ones don't.

