JavaScript Truthy vs Falsy: Why {}, [], and Even new Boolean(false) Are Truthy? Confused by JavaScript Booleans? Here's Why Boolean({}) and Boolean([]) Return True.

JavaScript Truthy vs Falsy Why carly bracket and sqare bracket and Even new Boolean false Are Truthy Confused by JavaScript Booleans Here is Why Boolean carly bracket and Boolean sqare bracket Return True

Our code :-

console.log(Boolean({}));
console.log(Boolean([])); console.log(Boolean("")); Boolean(new Boolean(false));

Line 1: console.log(Boolean({}))

What's Happening?

  • {} is an empty object.

In JavaScript:

  • All objects are truthy, even empty ones.
  • Boolean({})true

Output: true


Line 2: console.log(Boolean([]))

What's Happening?

  • [] is an empty array, which is also an object.

Again:

  • All objects are truthy, including arrays (even empty ones).
  • Boolean([])true

Output: true


Line 3: console.log(Boolean(""))

What's Happening?

  • "" is an empty string, which is one of the falsy primitive values in JavaScript.

List of falsy values includes:

  • false, 0, "", null, undefined, NaN

So:

  • Boolean("")false

Output: false


Line 4: Boolean(new Boolean(false))

This is super tricky and often misunderstood.

What’s going on?

  • new Boolean(false) creates a Boolean object, not a primitive.
  • It wraps the value false, but it's still an object.

Remember:

All objects are truthy, even if they represent a falsy value.

So:

Boolean(new Boolean(false)) → true

💡 Note: This line does not log anything because it’s not inside console.log(), but the value is true.


Key points :-

  • Primitive false is falsy, but new Boolean(false) is an object, which is truthy.
  • Avoid new Boolean(), new String(), and new Number() — they create wrapper objects that can lead to unexpected behavior.
  • Use Boolean(value) or !!value to test truthiness reliably.

✔ Final Answer:

true // Line 1
true // Line 2 false // Line 3 // Line 4 does nothing visible, but returns true

B) true true false true

NOTE :- when we run our code on browser console, we got above output where below code print true.

Boolean(new Boolean(false));

This question appeared in the Publicis Sapient 2nd round of interview, testing the candidate’s knowledge of type coercion in JavaScript.

Post a Comment

Previous Post Next Post