Logo

ToolsKit Plus

Search tools
Ctrl K
Favoritekofi

JavaScript Truthy Falsy Visualizer

Inspect and visualize truthy/falsy values and type coercion in JavaScript

JavaScript Truthy Falsy Visualizer is a free online tool to explore how different values behave in Boolean contexts. Inspect types, constructors, and results of Number and String conversion.

Categories
Javascript Tools
Enter JavaScript Expression

What is JavaScript Truthy Falsy Visualizer?

JavaScript Truthy Falsy Visualizer is an educational and debugging tool that helps you understand how JavaScript evaluates different values in a boolean context. In JavaScript, a "truthy" value is a value that is considered true when encountered in a Boolean context, while a "falsy" value is considered false.

Understanding these concepts is critical for writing clean conditional logic and avoiding common bugs related to type coercion.

How to Use

  1. Enter an Expression: Type any JavaScript literal or expression into the input box (e.g., [], 0, "", null).
  2. View Summary: The tool immediately shows whether the value is TRUTHY or FALSY.
  3. Inspect Transitions:
    • Type: See the result of the typeof operator.
    • Constructor: Identify the constructor function of the value.
    • Coercion: Observe how the value transforms when explicitly converted using Boolean(), Number(), and String().
  4. Use Presets: Click on the "Presets" tab to quickly explore famous "gotcha" cases in JavaScript.

Basic Knowledge: Truthy vs. Falsy

What are Falsy values?

There are exactly eight falsy values in JavaScript:

  • false: The keyword false.
  • 0: The number zero.
  • -0: The number negative zero.
  • 0n: BigInt zero (if your environment supports it).
  • "": An empty string.
  • null: The absence of any value.
  • undefined: A variable that has not been assigned a value.
  • NaN: Not-a-Number.

What are Truthy values?

Everything else is truthy. This includes:

  • '0': The string containing "0" is truthy.
  • 'false': The string "false" is truthy.
  • []: An empty array is truthy.
  • {}: An empty object is truthy.
  • Infinity: Positive infinity is truthy.

Why Does This Matter?

Type coercion can lead to unexpected results in if statements. For example:

const myArray = [];
if (myArray) {
  // This code WILL run because [] is truthy!
}

const myNumber = 0;
if (myNumber) {
  // This code WILL NOT run because 0 is falsy.
}

This tool helps you visualize these behaviors so you can write safer code, such as checking myArray.length > 0 instead of just if (myArray).

FAQ

Q: Is an empty array [] truthy or falsy?
A: An empty array is truthy. However, when compared with == 0, it becomes 0 due to coercion, which is a common source of confusion.

Q: Is NaN truthy?
A: No, NaN (Not-a-Number) is one of the eight falsy values in JavaScript.

Q: Does this tool run my code on a server?
A: No. All expressions are evaluated locally in your browser using the Function constructor. Your data never leaves your computer.

Q: Can I enter complex expressions like 1 + 2 * 3?
A: Yes! The tool can evaluate any valid JavaScript expression and show you the metadata of the resulting value.

Send Feedback

Help us improve! Share your thoughts or report an issue.

ToolsKit Plus
AboutTermsPrivacyContact

Copyright © 2022 - 2026 ToolsKit Plus. Unless otherwise noted, all code MIT license.


Made with by Complete JavaScript