VOOZH about

URL: https://www.geeksforgeeks.org/javascript/explain-the-concept-of-truthy-falsy-values-in-javascript/

⇱ Explain The Concept of Truthy & Falsy Values in JavaScript - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Explain The Concept of Truthy & Falsy Values in JavaScript

Last Updated : 5 Aug, 2025

In JavaScript, truthy and falsy values are concepts related to boolean evaluation. Every value in JavaScript has an inherent boolean "truthiness" or "falsiness," which means they can be implicitly evaluated to true or false in boolean contexts, such as in conditional statements or logical operations.

What Are Truthy Values?

Truthy values are values that are evaluated to be true when used in a Boolean context. Simply put, any value that is not explicitly falsy is considered truthy.

These are some truthy values


Output
This is truthy!
Non-empty strings are truthy!
Objects are truthy!

What Are Falsy Values?

Falsy values are values that evaluate to false when used in a Boolean. JavaScript has a fixed list of falsy values

  • false
  • 0 (and -0)
  • 0n (BigInt zero)
  • "" (empty string)
  • null
  • undefined
  • NaN
  • document.all (used for backward compatibility)

Truthy vs. Falsy Evaluation in JavaScript

Whenever JavaScript evaluates an expression in a Boolean (e.g., in an if statement, a logical operator, or a loop condition), it implicitly converts the value into true or false based on whether it is truthy or falsy.

With if Statement


Output
Truthy!

Logical Operators with Truthy and Falsy

Logical operators like && (AND) and || (OR) work with truthy and falsy values

  • && (AND): Returns the first falsy operand or the last operand if all are truthy.
  • || (OR): Returns the first truthy operand or the last operand if all are falsy.

Output
JavaScript
Hello!
null

Explicit Boolean Conversion

You can explicitly check whether a value is truthy or falsy using the Boolean() function or the double negation operator (!!).


Output
true
false
true
false
true
false

Common Pitfalls and Misunderstandings

Empty Strings vs. Non-Empty Strings

  • "" (empty string) is falsy.
  • " " (string with a space) is truthy.

Output
Truthy

Zero (0) vs. Non-Zero Numbers

0 is falsy, but -1, 3.14, and other numbers are truthy.


Output
Truthy

Empty Objects and Arrays Are Truthy

Unlike Python, where empty containers are falsy, empty objects {} and arrays [] are truthy in JavaScript.


Output
Empty arrays are truthy!
Empty objects are truthy!

Practical Applications

Default Values Using Logical OR (||)

The || operator is commonly used to assign default values when a variable is falsy.


Output
Guest

Conditional Property Access

Truthy and falsy checks can be used to avoid errors when accessing object properties:

Avoiding Explicit Comparisons

Truthy and falsy values allow concise conditions without explicit equality checks:

Difference Between Truthy and Falsy Values

AspectTruthy ValuesFalsy Values
DefinitionValues that evaluate to true in Boolean contexts. Values that evaluate to false in Boolean contexts.
Examples42, "hello", {}, [], function() {}false, 0, -0, "", null, undefined, NaN
Empty StructuresEmpty objects {} and arrays [] are truthy.Not applicable (empty structures are not falsy).
Strings

Non-empty strings (e.g., "hello", " ") are truthy.

Empty strings ("") are falsy.

Numbers

Non-zero numbers (e.g., 42, -3.14) are truthy.

Zero (0, -0) is falsy.

BigIntAny non-zero BigInt value (e.g., 10n) is truthy.Zero BigInt (0n) is falsy.
Usage in Logical OperatorsCan short-circuit `

Related Articles

Comment