Boolean Coercion
Predict Output Medium
Question
What does this code print?
Code
console.log(Boolean("") === Boolean(0));
Hint
Both "" and 0 are falsy, so Boolean gives false for both.
Explanation
Boolean("") is false and Boolean(0) is false, so false === false is true. Both empty string and 0 are falsy values in JavaScript. The falsy values are: false, 0, -0, 0n, "", null, undefined, NaN.
Related Resources
Related Lessons
- Conditions
Learn JS conditions.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.