> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/type/falsy.md).

# falsy

only 7 "falsy" values in JS.

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [type](/web/js/val/type.md) ⟩ [conversion](/web/js/val/type/convert.md) ⟩ falsy

{% hint style="success" %} <mark style="color:red;">**7**</mark> <mark style="color:purple;">**falsy**</mark>**&#x20;**<mark style="color:yellow;">**values：(converts to**</mark>**&#x20;**<mark style="color:red;">**false**</mark><mark style="color:yellow;">**)**</mark>

* <mark style="color:red;">**`false`**</mark>, <mark style="color:red;">**`0`**</mark>, [<mark style="color:red;">**`0n`**</mark>](/web/js/val/prim/bigint.md), <mark style="color:blue;">**`null`**</mark>, [<mark style="color:blue;">**`undefined`**</mark>](/web/js/val/prim/undefined.md), [<mark style="color:blue;">**`NaN`**</mark>](/web/js/val/prim/num/special/nan.md), <mark style="color:orange;">`""`</mark> (empty string).

<mark style="color:red;">**any other**</mark>**&#x20;**<mark style="color:yellow;">**value**</mark>**&#x20;is "**<mark style="color:green;">**truthy**</mark>**", and converts to&#x20;**<mark style="color:green;">**true**</mark>**.**
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="info" %} <mark style="color:yellow;">**every**</mark> [value](/web/js/val.md) <mark style="color:yellow;">**is either**</mark> <mark style="color:green;">**truthy**</mark> <mark style="color:yellow;">**or**</mark> <mark style="color:purple;">**falsy**</mark>:exclamation:
{% endhint %}

{% hint style="info" %} <mark style="color:red;">**all**</mark>**&#x20;**<mark style="color:yellow;">**objects**</mark>**&#x20;are** [<mark style="color:green;">**truthy**</mark>](/web/js/val/type/falsy.md) (<mark style="color:yellow;">**convert**</mark> to <mark style="color:green;">**true**</mark>).
{% endhint %}

{% hint style="danger" %}
&#x20;[operator](/web/js/grammar/op.md)(s) that expect [<mark style="color:yellow;">**boolean**</mark>](/web/js/val/prim/boolean.md) operands will work with an operand of <mark style="color:red;">**any**</mark>**&#x20;**<mark style="color:yellow;">**type**</mark>:exclamation:
{% endhint %}
{% endtab %}

{% tab title="👥 相關" %}

* [Boolean](/web/js/val/prim/boolean.md)
* [arr.filter()](/web/js/val/builtin/arr/method/arr.filter.md) - remove <mark style="color:purple;">**falsy**</mark> values.
  {% endtab %}

{% tab title="💈範例" %}

```javascript
'0' == false                // true❗️
if ('0') console.log('hi')  // hi  (⭐️ '0' is truthy❗️)

'0' === false               // false❗️

// facts about empty array
[] == ![]                   // true❗️
[] == []                    // false❗️
Boolean([])                 // true
Boolean(![])                // false❗️
```

{% endtab %}

{% tab title="📗 參考" %}

* [x] sitepoint ⟩ [Truthy and Falsy: When All is Not Equal in JavaScript](https://www.sitepoint.com/javascript-truthy-falsy/)
  {% endtab %}

{% tab title=" 🗣 討論" %}

* [In JavaScript, why is "0" equal to false, but when tested by 'if' it is not false by itself?](https://stackoverflow.com/questions/7615214/in-javascript-why-is-0-equal-to-false-but-when-tested-by-if-it-is-not-fals)
  {% endtab %}
  {% endtabs %}
