---
description: 🚧 under construction
---

# if

[JS](../../../..) ⟩ [statement](../..) ⟩ [control flow](..) ⟩ [branch]() ⟩ if

{% hint style="success" %}
([..](../.. "mention"))&#x20;

```javascript
if (condition) statement                     // one-way branch
if (condition) statement1 else statement2    // two-way branch
```
{% endhint %}

{% tabs %}
{% tab title="🧨 雷區" %}
{% hint style="danger" %}
<mark style="color:purple;">**else**</mark>**&#x20;**<mark style="color:orange;">**clause**</mark> is <mark style="color:yellow;">**part of**</mark> the <mark style="color:yellow;">**nearest**</mark> <mark style="color:purple;">**if**</mark> statement.

```javascript
if (expr1) statement1    // not this one
    if (expr2) statement2      // ... is part of this if statement
    else statement3            // else clause ...
```
{% endhint %}
{% endtab %}

{% tab title="👥 相關" %}
* [switch](switch "mention") - multiway branches.
* [falsy](../../../../val/type/falsy "mention") values.
{% endtab %}

{% tab title="📗 參考" %}
* [javascript-the-definitive-guide](../../../../../master/ref/javascript-the-definitive-guide "mention") ⟩ 5.3.1 if
{% endtab %}

{% tab title="📘 手冊" %}
* [ ] [Statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements) ⟩ [control flow](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#control_flow) ⟩ if
{% endtab %}
{% endtabs %}
