# Truthy and falsy values in JavaScript

> In JavaScript, values like 0, empty strings, null, and undefined are falsy, while almost everything else is truthy. Here's how this affects your conditionals.

Published: 2023-01-23T09:44:16.000Z
Updated: 2026-04-24T10:00:00.000Z
Author: Shameem Reza
Category: Development
Canonical: https://shameemreza.com/truthy-and-falsy-values-in-javascript/

---

import Tldr from '../../components/Tldr.astro';

Every JavaScript conditional asks the same question: is this value truthy or falsy? The answer isn't always obvious. An empty array is truthy. The string `"0"` is truthy. The number `-1` is truthy. But the number `0`, the empty string, and `null` are all falsy. Once you know the exact list, the rest of the language stops surprising you.

<Tldr>
  There are exactly six falsy values in JavaScript: `false`, `0` (including `-0` and `0n`), `""`, `null`, `undefined`, and `NaN`. Everything else is truthy, including empty arrays, empty objects, and the string `"0"`. In any boolean context (`if`, `&&`, `||`, `!`, ternary), JavaScript coerces to one of those two sides. To check a specific value, use `Boolean(value)` or a plain `if (value)`.
</Tldr>

## What are truthy and falsy values in JavaScript?


In [JavaScript](/strict-vs-loose-equality-in-javascript/), a truthy value is any value that evaluates to true when used in a boolean context. For example, the number 1, the string `"hello"`, and `the array [1, 2, 3]` are all truthy values.

On the other hand, a falsy value is any value that evaluates to false when used in a boolean context. Some common falsy values include the number 0, the `empty string ""`, and the special keyword null.

Not every value behaves the way you'd expect. The number `-1` is truthy, even though it's not positive. The keyword `undefined` is falsy, even though it isn't `0` or an empty string. The list of falsy values is short and worth memorizing, because everything outside that list is truthy.

## How to use truthy and falsy values in JavaScript


One of the most common ways to use truthy and falsy values in JavaScript is in conditional statements. For example, consider the following if-else statement:

```
let x = 0;
if (x) {
  console.log("x is truthy");
} else {
  console.log("x is falsy");
}
```


In this example, the variable `x` is assigned the value 0, which is a falsy value. Therefore, the code inside the else block will be executed, and the string `"x is falsy"` will be logged to the console.

Another common use is with the logical operators `&&` and `||`. The code below logs `"hello"` when `name` is truthy and `"world"` when it's falsy:

```
let name = "John";
console.log(name && "hello" || "world");
```

Since `name` is truthy, `name && "hello"` resolves to `"hello"`. Then `"hello" || "world"` short-circuits on the first truthy value and returns `"hello"`. If you set `name = ""`, the same expression returns `"world"` instead.

## How to check if a value is truthy or falsy in JavaScript


In JavaScript, you can check if a value is truthy or falsy by using the if statement or the Boolean() function.

### Using the if statement



```
let x = 0;
if (x) {
  console.log("x is truthy");
} else {
  console.log("x is falsy");
}
```


In this example, the variable `x` is assigned the value `0`, which is a falsy value. Therefore, the code inside the else block will be executed, and the string `"x is falsy"` will be logged to the console.

### Using the Boolean() function



```
let x = 0;
console.log(Boolean(x)); //outputs false
```


The `Boolean()` function is a built-in JavaScript function that returns the boolean value of the given expression. If the value passed to it is a truthy value, it will return true; if the value passed is falsy, it will return false.

## What are the falsy values in JavaScript?


In JavaScript, the list of falsy values is short. These are the values that evaluate to `false` in a boolean context:

- `false`, the boolean literal.
- `0`, the number zero, including `-0` and `0n` (BigInt zero).
- `""`, an empty string (also `''` and the empty template literal).
- `null`.
- `undefined`.
- `NaN`, the special "Not a Number" value.


Anything not in that list is truthy. That includes things people often trip over, like an empty object `\{\}` or an empty array `[]`. Both are truthy, even though they hold nothing. So is the string `"0"`, because it's a non-empty string, not the number zero.

## Is an empty object truthy or falsy in JavaScript?


In JavaScript, an empty object `\{\}` is considered a truthy value. This is because, in JavaScript, all objects are considered truthy values and will evaluate to true when used in a boolean context.

It means that if you use an empty object in a conditional statement or a logical operator, it will be treated as a true value.

```
if({}){
 console.log("This is truthy value")
}
```


In this example, the if statement will execute and log `"This is truthy value"` to the console.

A quick mental checklist: the six falsy values are `false`, `0`, `""`, `null`, `undefined`, and `NaN`. Everything else is truthy, including `-1`, `"false"` as a string, empty arrays, empty objects, and functions. When the truthiness of a value matters, `Boolean(value)` or a plain `if (value)` will tell you which side of the line it falls on.

For the deeper formal definition, MDN has a [concise reference on truthy and falsy values](https://developer.mozilla.org/en-US/docs/Glossary/Truthy).
