If you’ve been writing JavaScript for a while, you’ve probably seen code like this:

if (user) {
    console.log("User exists");
}

But what exactly is JavaScript checking here?

Is user equal to true? Not necessarily.

Instead, JavaScript determines whether the value is truthy or falsy.

Understanding truthy and falsy values in JavaScript is one of the most important fundamentals for every developer. These concepts appear everywhere—from if statements and loops to React conditional rendering, Node.js applications, and JavaScript interviews.

In this guide, you’ll learn what truthy and falsy values are, see the complete list of falsy values, understand why empty arrays are truthy, and explore the !! (double bang) operator, and learn how modern JavaScript operators like ||=, &&=, and ??= rely on truthy and falsy evaluations.



What Are Truthy and Falsy Values?

In JavaScript, every value has an inherent boolean representation.

When JavaScript evaluates a condition, it doesn’t require the value to literally be true or false. Instead, it converts the value into a boolean behind the scenes.

For example:

const username = "John";

if (username) {
    console.log("Welcome!");
}

Output:

Welcome!

Although "John" isn’t the boolean value true, JavaScript treats it as truthy, so the condition executes.

This automatic conversion is called Boolean coercion.

20 Essential Questions JavaScript Interview Questions


The Complete List of Falsy Values

One of the easiest JavaScript interview questions is:

How many falsy values are there in JavaScript?

There are 8 falsy values in modern JavaScript.

ValueDescription
falseBoolean false
0Number zero
-0Negative zero
0nBigInt zero
""Empty string
nullIntentional absence of value
undefinedVariable without a value
NaNNot a Number

These are the only falsy values.

Everything else is truthy.

Example:

console.log(Boolean(0));
console.log(Boolean(""));
console.log(Boolean(null));
console.log(Boolean(undefined));

Output:

false
false
false
false

Common Truthy Values

Many developers assume certain values are falsy when they’re actually truthy.

Here are some examples.

ValueTruthy or Falsy
"false"Truthy
"0"Truthy
" " (space)Truthy
[]Truthy
{}Truthy
function(){}Truthy
InfinityTruthy
-1Truthy

Example:

if ("false") {
    console.log("Runs");
}

Output:

Runs

Even though the string contains the word "false", it’s still a non-empty string, making it truthy.


Truthy vs Falsy Examples

Understanding real examples makes these concepts much easier.

Example 1

if (0) {
    console.log("Hello");
}

Nothing is printed because 0 is falsy.


Example 2

if ("Hello") {
    console.log("Hello");
}

Output:

Hello

A non-empty string is truthy.


Example 3

if ([]) {
    console.log("Array exists");
}

Output:

Array exists

An empty array is truthy.


Example 4

if ({}) {
    console.log("Object exists");
}

Output:

Object exists

An empty object is also truthy.


Why Are Empty Arrays and Objects Truthy?

This is one of the most frequently asked JavaScript interview questions.

Many beginners expect:

[]

to behave like:

false

However:

Boolean([]);

returns:

true

The same applies to objects:

Boolean({});

returns:

true

Why?

Because arrays and objects are reference types.

Even when they’re empty, they still reference a valid object in memory.

JavaScript only considers the finite list of falsy values as false. Since arrays and objects aren’t on that list, they’re truthy.


Boolean Conversion and the Double Bang (!!) Operator

Sometimes you want to convert any value into a true boolean.

The simplest way is with the double bang (!!) operator.

Example:

const username = "Alice";

console.log(!!username);

Output:

true

Another example:

console.log(!!0);

Output:

false

The first ! converts the value to its opposite boolean.

The second ! reverses it again, leaving you with the actual boolean representation.

This technique is widely used in React, Vue, Angular, and Node.js applications.


Logical Assignment Operators (||=, &&=, ??=)

Modern JavaScript introduced logical assignment operators that rely heavily on truthy and falsy evaluations.

OR Assignment (||=)

let username = "";

username ||= "Guest";

console.log(username);

Output:

Guest

Because the empty string is falsy.


AND Assignment (&&=)

let isAdmin = true;

isAdmin &&= false;

console.log(isAdmin);

Output:

false

The assignment only occurs because the original value is truthy.


Nullish Assignment (??=)

let language = null;

language ??= "English";

console.log(language);

Output:

English

Unlike ||=, the ??= operator only checks for null and undefined.

This makes it much safer when 0, false, or an empty string are valid values.


Practical Use Cases

Truthy and falsy values appear throughout modern JavaScript development.

Conditional Rendering

if (user) {
    showDashboard();
}

Default Values

const name = username || "Guest";

Modern Default Values

const name = username ?? "Guest";

This preserves values like:

  • 0
  • false
  • ""

while only replacing null and undefined.


Form Validation

if (!email) {
    alert("Email is required");
}

React Conditional Rendering

{user && <Dashboard />}

React developers use truthy and falsy evaluations constantly.


Truthy vs Falsy: Quick Comparison

TruthyFalsy
"Hello"""
"0"0
[]null
{}undefined
1NaN
truefalse
-100n

Best Practices

When working with truthy and falsy values:

  • Know the complete list of falsy values.
  • Don’t assume empty arrays or objects are falsy.
  • Use !! when you explicitly need a boolean.
  • Prefer ?? over || when handling null or undefined.
  • Use logical assignment operators (||=, &&=, ??=) appropriately.
  • Write conditions that clearly express your intent instead of relying on implicit conversions where readability suffers.

Frequently Asked Questions

What are truthy and falsy values in JavaScript?

Truthy values evaluate to true in a boolean context, while falsy values evaluate to false.


How many falsy values are there in JavaScript?

There are 8 falsy values in modern JavaScript:

  • false
  • 0
  • -0
  • 0n
  • ""
  • null
  • undefined
  • NaN

Is an empty array truthy or falsy?

An empty array ([]) is truthy because it is still a valid object reference.


Is an empty object truthy or falsy?

An empty object ({}) is truthy for the same reason—it is a valid object in memory.


What does the !! operator do?

The double bang operator converts any value into its boolean equivalent.

Example:

!!"Hello"

returns:

true

Additional Learning Resources

To learn more about JavaScript boolean conversions and conditional logic, explore these trusted resources:


Related Articles

Continue strengthening your JavaScript fundamentals with these topics:

  • Null vs Undefined in JavaScript
  • Difference Between == and ===
  • JavaScript Data Types Explained
  • Optional Chaining (?.) Explained
  • Nullish Coalescing (??) Explained
  • JavaScript Logical Operators
  • Difference Between var, let, and const

Final Thoughts

Understanding truthy and falsy values in JavaScript is fundamental to writing clean, reliable, and bug-free code.

Remember these key takeaways:

  • JavaScript automatically converts values to true or false in conditional statements.
  • There are only 8 falsy values in modern JavaScript.
  • Empty arrays ([]) and empty objects ({}) are truthy, even though they’re empty.
  • The !! operator is a simple way to convert any value into a boolean.
  • Modern operators like ||=, &&=, and ??= depend on truthy and falsy evaluations, making this concept more relevant than ever.

Whether you’re preparing for a JavaScript interview or building production applications, mastering truthy and falsy values will help you write more predictable code and avoid subtle bugs that are often difficult to debug.