# +，-，\*\* 运算符

## 一元运算符 +

一元 `+` 运算符将其操作数转换为数字类型。

```javascript
+"23" // 23
+{} // NaN
+null // 0
+undefined // NaN
+{ valueOf: () => 67 } // 67
+"nnamdi45" // NaN
复制代码
```

当我们希望将变量快速转换为 `Number` 时，这非常方便。

## 一元运算符 -

**一元运算符 `-` 将其操作数转换为 `Number` 类型，然后取反。**

该运算符将一元 `+` 运算符的结果取反。 首先，它将操作数转换为其 `Number` 值，然后取反该值。

```javascript
-"23" // -23
```

此处发生的是，字符串 `"23"` 将转换为其数字类型，从而得到 `23` 。然后，此正数将转换为其负数形式 `-23` 。

```javascript
-{} // NaN
-null // -0
-undefined // NaN
-{ valueOf: () => 67 } // -67
-"nnamdi45" // NaN
```

如果转换为数值的结果为 `NaN` ，则不会应用取反。

取负 `+0` 产生 `-0` ，取负 `-0` 产生 `+0` 。

```javascript
- +0 // -0
- -0 // 0
```

## 指数运算符 \*\*

该运算符用于指定数字的指数。

在数学中， 2^3^ 意味着将 2 乘以三次：

```javascript
2 * 2 * 2
```

我们可以使用 `**` 运算符在 JS 中进行相同的操作：

```javascript
2 ** 3 // 8
9 ** 3 // 729
```

<br>


---

# 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://mm.ricky.moe/javascript/es6-1/+-yun-suan-fu.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.
