JavaScript · JS Tutorial · Lesson 26
JS Booleans
true, false, truthy and falsy values.
A JavaScript Boolean represents one of two values: true or false. The Boolean() function shows whether an expression is true.
Example
<p id="demo"></p>
<script>
let out = "";
out += "10 > 9: " + (10 > 9) + "<br>";
out += "Boolean(100): " + Boolean(100) + "<br>";
out += "Boolean(0): " + Boolean(0) + "<br>";
out += "Boolean(\"\"): " + Boolean("") + "<br>";
out += "Boolean(\"false\"): " + Boolean("false") + "<br>";
out += "Boolean(null): " + Boolean(null) + "<br>";
out += "Boolean(NaN): " + Boolean(NaN);
document.getElementById("demo").innerHTML = out;
</script>
Falsy values: false, 0, -0, 0n, "", null, undefined and NaN. Everything else is truthy.
Keep reading “JS Booleans”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.