loader

Loading

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup

Introduction

Quick StartWhat is JavaScriptHistory of JavaScript

Setup

Node.js InstallationVisual Studio Code

Basics

Syntax & Comments
Variables
Functions
JavaScript StringsJavaScripit ArraysLoops with ArraysMap, Filter, and ReduceDate in JavaScriptMath in JavaScriptNumber in JavaScriptBoolean in JavaScript

Advanced

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup
TutorialsJavaScript TutorialObjectsBoolean in JavaScript

Boolean in JavaScript

In this tutorial, we will learn how to work with booleans in JavaScript using the Boolean object.

In JavaScript, the Boolean object is used to work with boolean values. It provides methods for converting values to booleans and performing logical operations.

Converting Values to Booleans

The Boolean object provides methods for converting values to booleans. You can use the Boolean() constructor or the !! operator to convert values to booleans. Here are some examples:

Boolean()

The Boolean() constructor converts a value to a boolean. If the value is truthy, it will be converted to true; otherwise, it will be converted to false.

let num = 42;
console.log(Boolean(num)); // true

Another example:

let isTrue = Boolean(1);
console.log(isTrue); // Output: true

let isFalse = Boolean(0);
console.log(isFalse); // Output: false

!! shorthand

The !! operator is a shorthand way to convert a value to a boolean. It is equivalent to using the Boolean() constructor.

let str = "hello";
console.log(!!str); // true

Logical Operations

The Boolean object provides methods for performing logical operations. You can use the && (logical AND), || (logical OR), and ! (logical NOT) operators to combine boolean values. Here are some examples:

Logical AND (&&)

The && operator returns true if both operands are true; otherwise, it returns false.

let a = true;
let b = false;
console.log(a && b); // false

Logical OR (||)

The || operator returns true if either operand is true; otherwise, it returns false.

let a = true;
let b = false;
console.log(a || b); // true

Logical NOT (!)

The ! operator returns the opposite boolean value of the operand. If the operand is true, it returns false; if the operand is false, it returns true.

let a = true;
console.log(!a); // false

Conclusion

  • The Boolean object is used to work with boolean values in JavaScript.
  • You can convert values to booleans using the Boolean() constructor or the !! operator.
  • You can perform logical operations using the &&, ||, and ! operators.
  • Boolean values are often used in conditional statements and loops to control the flow of the program.
  • Understanding boolean values and logical operations is essential for writing effective JavaScript code.

How is this guide?

February 26th, 2026

Number in JavaScript

In this tutorial, we will learn how to work with numbers in JavaScript using the Number object.

Window Object

In this tutorial, we will learn about the Window object in JavaScript.

© 2026CoderrShyamAll Rights Reserved.

On this page

Converting Values to Booleans
Boolean()
!! shorthand
Logical Operations
Logical AND (&&)
Logical OR (||)
Logical NOT (!)
Conclusion
Follow us on GitHub