true, false, truthy and falsy.
A boolean is either true or false. Comparisons produce booleans.
Truthy and falsy
In conditions, every value acts as true or false. These values are falsy :
false, 0, "" (empty string), null, undefined, NaN
Everything else is truthy , including "0", [] and {}.
💡 Key Takeaways: JavaScript Booleans & Comparisons
Mastering JavaScript Booleans & Comparisons helps you write clean and reliable JavaScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
JavaScript Booleans & Comparisons Code Example
JavaScript
<pre id="out"></pre>
<script>
const log = (...a) => document.getElementById("out").textContent += a.join(" ") + "\n";
log("10 > 9:", 10 > 9);
log("'apple' < 'banana':", "apple" < "banana");
const values = [0, 1, "", "hello", null, undefined, NaN, [], {}];
for (const v of values) {
log(JSON.stringify(v) ?? String(v), "is", v ? "truthy" : "falsy");
}
log(Boolean("0"));
</script>
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services