J

JavaScript Handbook

Clean • Professional

JavaScript Booleans — Top Interview Questions & Answers

3 minute

JavaScript Booleans — Interview Questions & Answers

Ques: What is a Boolean in JavaScript?

Ans: A Boolean is a data type that can have only two valuestrue or false.

Booleans are mainly used for conditional testing, logical operations, and control flow.

Example:

let isOnline = true;
let hasAccess = false;

Ques: What is the type of a Boolean value?

typeof true;   // "boolean"
typeof false;  // "boolean"

Ques: What values are considered truthy or falsy in JavaScript?

JavaScript automatically converts values to Boolean when needed (type coercion).

Falsy ValuesTruthy Values
falseEverything not falsy
0true
-042
"" (empty string)"hello"
null[], {}
undefined"0", "false"
NaNany non-empty object

Example:

if (0) console.log("This won’t run");
if ("hello") console.log("This will run");

Ques: How can you convert a value to Boolean explicitly?

  1. Using the Boolean() function

    Boolean(10);       // true
    Boolean("");       // false
    
  2. Using double NOT (!!) operator

    !!"text";          // true
    !!0;               // false
    

Ques: What is the difference between Boolean object and Boolean primitive?

FeatureBoolean PrimitiveBoolean Object
Created withtrue, falsenew Boolean(value)
Type"boolean""object"
Exampletypeof true"boolean"typeof new Boolean(false)"object"

Example:

let x = false;
let y = new Boolean(false);

console.log(typeof x); // "boolean"
console.log(typeof y); // "object"

Boolean objects are truthy, even if the value is false.

if (new Boolean(false)) console.log("This runs!"); // true

Ques: How are Booleans used in conditions?

Ans: Booleans are used to control the flow of code in if-else, loops, and ternary operators.

let isLoggedIn = true;

if (isLoggedIn) {
  console.log("Welcome user!");
} else {
  console.log("Please login.");
}

Ques: How do you compare Boolean values?

true == 1;   // true (loose equality)
true === 1;  // false (strict equality)
false == 0;  // true
false === 0; // false

Ques: How to check if a variable is Boolean?

typeof value === "boolean";  // true or false

Ques: What is Boolean coercion in JavaScript?

Ans: When JavaScript automatically converts other data types into Boolean values in a logical context.

Example:

if ("hello") console.log("Truthy");  // "hello" → true
if (0) console.log("Falsy");         // 0 → false

Ques: What are common Boolean operations in JS?

OperatorDescriptionExampleResult
&&Logical ANDtrue && falsefalse
` `Logical OR
!Logical NOT!truefalse

Ques: What is short-circuit evaluation?

Ans: JS stops evaluating a logical expression as soon as the result is known.

Example:

false && console.log("Skipped"); // Skipped is NOT printed
true  || console.log("Skipped"); // Skipped is NOT printed

Ques: What’s the difference between Boolean(value) and !!value?

Both convert a value to Boolean, but:

MethodOutput TypeExample
Boolean("Hi")trueConverts directly
!!"Hi"trueUses NOT twice for coercion

Ques: Can Booleans be used in arithmetic operations?

Ans: Yes, In numeric context, true → 1 and false → 0.

Example:

console.log(true + true);  // 2
console.log(false + 5);    // 5

Ques: How do you toggle a Boolean value?

let flag = true;
flag = !flag;   // toggles between true ↔ false

Ques: What is Boolean casting in JavaScript?

Ans: Casting means converting a non-boolean value into Boolean using:

Boolean(value);
!!value;

Ques: What’s the difference between null, undefined, and false in Boolean context?

ValueBoolean Result
nullfalse
undefinedfalse
falsefalse
0false

Ques: What happens if you use Boolean in string concatenation?

Ans: Booleans are automatically converted to strings when concatenated.

"Result: " + true; // "Result: true"

Ques: How are Booleans stored internally?

Ans: Booleans are stored as binary values1 for true, 0 for false.

Article 0 of 0