> For the complete documentation index, see [llms.txt](https://radlohead.gitbook.io/typescript-deep-dive/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://radlohead.gitbook.io/typescript-deep-dive/recap/truthy.md).

# Truthy

자바스크립트에는 `truthy`라는 개념이 있다. 특정위치에서 그렇게 동작하는데 (예: `if`, `&&` `||`연산자)가 이에 해당한다. 실제로는 `true`가 아니지만 그렇게 동작한다는 것인데 숫자를 예를 들면 `0`이 아닌 모든 값은 `true`인 경우가 그 예이다.

```typescript
if (123) {
    // Will be treated like `true`
    console.log('Any number other than 0 is truthy')
}
```

truthy가 아닌 것을 `falsy`라 부릅니다.

여기 참고할 수 있는 편리한 표가 있다. Here's a handy table for your reference.

| Variable Type                                        | When it is *falsy*  | When it is *truthy* |
| ---------------------------------------------------- | ------------------- | ------------------- |
| `boolean`                                            | `false`             | `true`              |
| `string`                                             | `''` (empty string) | any other string    |
| `number`                                             | `0` `NaN`           | any other number    |
| `null`                                               | always              | never               |
| `undefined`                                          | always              | never               |
| Any other Object including empty ones like `{}`,`[]` | never               | always              |

## 분명한 건

> `!!`패턴

일반적으로 `boolean`값으로 처리하고 `true`|`false`로 변환하는 것이 의도임을 아는 것이 중요합니다. 당신은 boolean값을 쉽게 얻을 수 있습니다. `!!`를 이용해서 예: `!!foo`. 그것은 `!`을 두번 사용해서 표현할 수 있습니다. 첫번째 `!`가 변수를 boolean 값을 반전시키지만 두번째 `!`가 다시 논리를 반전시키기 때문에 원래의 boolean값을 얻을 수 있습니다.

이런 패턴을 많은 곳에서 사용하는 것은 흔한 일입니다.

```javascript
// Direct variables
const hasName = !!name

// As members of objects
const someObj = {
    hasName: !!name
}

// e.g. in ReactJS JSX
{
    !!someName && <div>{someName}</div>
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://radlohead.gitbook.io/typescript-deep-dive/recap/truthy.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
