GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • JS Tutorial
  • Web Tutorial
  • A to Z Guide
  • Projects
  • OOP
  • DOM
  • Set
  • Map
  • Math
  • Number
  • Boolean
  • Exercise
  • truthy
  • falsy

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — JavaScript Boolean - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • JS Tutorial
  • Web Tutorial
  • A to Z Guide
  • Projects
  • OOP
  • DOM
  • Set
  • Map
  • Math
  • Number
  • Boolean
  • Exercise

JavaScript Boolean

Last Updated : 11 Jul, 2025

To represent logical values, JavaScript uses the Boolean data type, which has two possible values: true or false. These values often result from comparisons or logical operations. Additionally, the Boolean() function can convert other types of values into Boolean, determining their truthy or falsy nature.

The Boolean() Function

The Boolean() function is used to explicitly convert a value to its Boolean equivalent. Truthy values return true, while falsy values return false.

JavaScript
console.log(Boolean("Hello"));
console.log(Boolean(0));    

Output
true
false
  • Non-empty strings like "Hello" are truthy.
  • Zero is a falsy value.

Everything With a "Value" is True

In JavaScript, all objects, arrays, and non-empty strings are considered truthy values.

JavaScript
console.log(Boolean({}));
console.log(Boolean([])); 
console.log(Boolean("Hi"));

Output
true
true
true

Objects and arrays always evaluate to true in Boolean contexts.

Everything Without a "Value" is False

Certain values, like 0, null, undefined, NaN, and empty strings, are falsy.

JavaScript
console.log(Boolean("") === false); 
console.log(Boolean(undefined)); 

Output
true
false

These values lack meaningful content and thus evaluate to false.

JavaScript Booleans as Objects

While JavaScript supports primitive Booleans, the Boolean constructor can create Boolean objects. However, these objects are truthy regardless of their value.

JavaScript
let obj = new Boolean(false);
console.log(obj);      
console.log(typeof obj); 
console.log(Boolean(obj));

Output
[Boolean: false]
object
true

Using new Boolean() is generally discouraged because it can lead to confusion.

Boolean Primitives

A Boolean primitive is a simple representation of true or false. This is the most commonly used Boolean type in JavaScript.

JavaScript
let isAvailable = true;
console.log(typeof isAvailable);

Output
boolean

Boolean primitives are lightweight and efficient for logical operations.

Boolean Coercion

JavaScript implicitly converts values to Boolean in contexts like conditions and loops.

JavaScript
let user = "";
if (user) {
    console.log("Valid input");
} else {
    console.log("Invalid input");
}

Output
Invalid input

Empty strings evaluate to false, so "Invalid input" is logged.

Constructor and Instance

The Boolean constructor can create Boolean objects, but primitive Booleans are preferred.

JavaScript
let primitiveBool = true;
let objBool = new Boolean(false);
console.log(typeof primitiveBool);
console.log(typeof objBool); 

Output
boolean
object

Primitive Booleans are easier to use and avoid unnecessary complexity.

Truthy and Falsy Values

Falsy Values: Values that are evaluated as false when used in a Boolean. Unlike truthy values, falsy values represent "nothingness," "emptiness," or "failure."

  • false
  • 0, -0
  • null
  • undefined
  • NaN
  • '' (empty string)

Truthy Values: Values that are evaluated to be true when used in a Boolean context, such as in conditional statements or logical operations.

  • Non-zero numbers (e.g., 1, -42)
  • Non-empty strings (e.g., 'Hello', ' ')
  • Objects and arrays ({}, [])

Truthy/Falsy in Action

JavaScript
console.log(Boolean(""));    
console.log(Boolean("text"));
console.log(Boolean(0));    
console.log(Boolean([]));  

Output
false
true
false
true
  • Empty strings and 0 are falsy.
  • Non-empty strings and arrays are truthy.

Boolean Coercion in Conditions

JavaScript
let age = 0;
if (age) {
    console.log("Age provided");
} else {
    console.log("Age missing");
}

Output
Age missing

Since userAge is 0, it evaluates to falsy, and "Age missing" is logged.

Practical Applications

1. Conditional Statements

JavaScript
let score = 70;
if (score >= 50) {
    console.log("Pass");
} else {
    console.log("Fail");
}

Output
Pass

2. Ternary Operator

JavaScript
let age = 16;
let isAdult = age >= 18 ? true : false;
console.log(isAdult);

Output
false

3. Logical Short-Circuiting

JavaScript
let defaultName = "Guest";
let userName = "" || defaultName;
console.log(userName);

Output
Guest

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.

Comment

Explore

    JavaScript Basics
    • Introduction3 min read
    • Variables5 min read
    • Operators4 min read
    • Control Statements4 min read
    Array & String
    • Arrays6 min read
    • Array Methods4 min read
    • String5 min read
    • String Methods8 min read
    Function & Object
    • Functions4 min read
    • Function Expression3 min read
    • Function Overloading4 min read
    • Objects4 min read
    • Constructors4 min read
    OOP
    • OOP5 min read
    • Classes & Objects4 min read
    • Access Modifiers5 min read
    • Constructor4 min read
    Asynchronous JavaScript
    • Asynchronous2 min read
    • Callbacks4 min read
    • Promises4 min read
    • Event Loop3 min read
    • Async Await Fuction3 min read
    Exception Handling
    • Error and Exceptional Handling5 min read
    • Errors Throw & Try to Catch2 min read
    • Custom Errors2 min read
    • TypeError Invalid Array.prototype.sort argument1 min read
    DOM
    • DOM8 min read
    • DOM Elements3 min read
    • Custom Events4 min read
    • Addeventlistener5 min read
    Advanced Topics
    • Closure3 min read
    • Hoisting5 min read
    • Scope4 min read
    • Higher Order Functions7 min read
    • Debugging3 min read
    Courses
    • Placement 360 Course2 min read
    • MERN Full Stack Course2 min read
    • DSA and System Design Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.