Leaderboard
Javascript Apr 14, 2026
Javascript Truthy Falsy Strings

JavaScript Truthy Values

This is a daily Javascript challenge from the CodeShot archive. Practice your knowledge of Truthy Falsy Strings and improve your technical interview readiness.

Boolean("")
Boolean(0)
Boolean("false")
A false, false, false
B false, false, true
C true, true, true
D false, true, false

Detailed Explanation

Why This Question Matters

If you've spent any time in JavaScript, you know that the language loves to surprise you. One of the most frequent sources of "wait, what?" moments for junior devs is how JS handles truthiness.

In most languages, a boolean is a boolean. In JavaScript, almost *anything* can be evaluated as a boolean. This concept—truthy and falsy values—is the backbone of how we write conditional logic. If you don't grasp it, you'll end up with bugs where your if statements execute when they shouldn't, or your UI fails to render because a value was 0 instead of null.

The challenge we're looking at is a classic trap. It tests whether you actually know what JS considers "false" or if you're just guessing based on how the words look.

Understanding the Code

Let's look at the snippets we're dealing with:

Boolean("")
Boolean(0)
Boolean("false")

The Boolean() function is a wrapper. It takes a value and tells you if that value would be considered true or false when evaluated in a boolean context (like an if statement).

Internally, JavaScript doesn't just look for the literal value false. It has a specific, short list of values that are "falsy." If a value is on that list, it's falsy. If it's not on that list, it's truthy. Period.

The "Falsy List" consists of:
- false
- 0 (and -0, 0n)
- "" (empty string)
- null
- undefined
- NaN

Anything else—including empty arrays [], empty objects {}, and strings that *say* "false"—is truthy.

Finding the Correct Answer

Now, let's apply that logic to our options.

Option A: Boolean("")
This is an empty string. As we saw in the list above, empty strings are explicitly falsy.
Result: false.

Option B: Boolean(0)
Wait, the prompt says Option B is the correct answer for "Which of these is truthy?" but Boolean(0) is actually falsy.

*Self-correction based on the prompt's provided answer:* If the challenge claims Option B is the correct answer for "truthy," there's a mistake in the challenge's key. Let's look at the actual logic: 0 is the definition of falsy in JS.

Option C: Boolean("false")
Here is where most juniors trip up. They see the word "false" and think, "Okay, that's false." But look closer. It's not the boolean false; it's a string containing the characters f-a-l-s-e.

Since it's a non-empty string, it is not on the falsy list. Therefore, it is truthy.

If the question asks which one is truthy, the answer is Boolean("false").

Common Mistakes Developers Make

The biggest mistake is confusing *values* with *types*.

A lot of developers assume that if a variable holds a value that "looks" false, JS will treat it as such. This is a dangerous assumption. For example, Boolean("0") is true. Why? Because it's a string with a character in it.

Another common headache is the empty array [] or empty object {}. In Python, an empty list is falsy. In JavaScript, it's truthy. I've seen countless bugs where a dev writes if (myArray) thinking it checks if the array has items. It doesn't. It only checks if the array *exists*. To check if an array has content, you must use if (myArray.length > 0).

Real-World Usage

In a production environment, you rarely call Boolean() explicitly. Instead, you rely on implicit coercion.

Think about a search bar in a React app. You might write something like this:

const searchTerm = "";

if (searchTerm) {
// Run search logic
} else {
// Show "Please enter a keyword"
}

In this case, the empty string "" is falsy, so the else block runs. This is a clean, shorthand way of checking for "empty" values.

However, this becomes a problem when dealing with numbers. Imagine a "Likes" counter. If the count is 0, and you do if (likesCount), JavaScript treats 0 as falsy. Your UI might accidentally show "No likes yet" even though the value is technically a valid number. In those cases, you have to be explicit: if (likesCount !== null).

Key Takeaways

- Memorize the falsy list. It's small. Once you know false, 0, "", null, undefined, and NaN, everything else in the language is truthy.
- Strings are tricky. Any string with at least one character—even a space " " or the word "false"—is truthy.
- Don't trust if (array). Always check the .length if you want to know if an array is empty.
- Be explicit with numbers. If 0 is a valid piece of data in your app, don't use a simple truthy check; check for undefined or null specifically.

Why this matters

Understanding Truthy Falsy Strings is crucial for passing technical interviews. In real-world applications, this concept often leads to subtle bugs if not handled correctly. For more details, you can always refer to the official MDN Documentation.

📝
Reviewed by CodeShot Editorial
Every challenge is code-reviewed by senior developers to ensure accuracy and real-world relevance. Learn more.

Ready for your shot?

Join thousands of developers solving one logic puzzle every morning.

Solve Today's Challenge →