# void

[JS](../../..) ⟩ [statement](../../statement) ⟩ [expression](../../statement/expr) ⟩ [operator](..) ⟩ [unary]() ⟩ void

{% hint style="success" %}
([..](.. "mention"))

<mark style="color:yellow;">**evaluates**</mark> its operand, then <mark style="color:red;">**discards**</mark>**&#x20;**<mark style="color:yellow;">**the value**</mark> and <mark style="color:yellow;">**returns**</mark> [undefined](../../../val/prim/undefined "mention").

```javascript
// ⭐ syntax: void <expr>
const count = () => void counter++;    // ⭐ void: discard return value
```
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}
* [void](https://replit.com/@pegasusroe/void#index.js) (replit)

```javascript
let counter = 0;

// ⭐ void: discard return value
const count = () => void counter++;
const count2 = () => { counter++ };    // same as above

count(),    // undefined
counter,    // 1

count2(),   // undefined
counter++,  // 2
```
{% endtab %}

{% tab title="📗 參考" %}
* [ ] [JS 冷知識：你所不知道的 void](https://kuro.tw/posts/2019/08/04/JS-%E5%86%B7%E7%9F%A5%E8%AD%98-%E4%BD%A0%E6%89%80%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84-void/)
* [ ] [javascript-the-definitive-guide](../../../../master/ref/javascript-the-definitive-guide "mention") ⟩ 4.13.6 The void Operator
{% endtab %}

{% tab title="📘 手冊" %}
* [void operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void) \
  <mark style="color:blue;">`void`</mark>` `<mark style="color:yellow;">`expr`</mark> or <mark style="color:blue;">`void(`</mark><mark style="color:yellow;">`expr`</mark><mark style="color:blue;">`)`</mark> <mark style="color:red;">**evaluates**</mark> the given <mark style="color:yellow;">`expr`</mark> and then returns [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined).
{% endtab %}

{% tab title="👥 相關" %}
* some [transpilers](../../../tools/transpilers "mention") turn <mark style="color:purple;">undefined</mark> into <mark style="color:yellow;">**void 0**</mark>.
{% endtab %}
{% endtabs %}
