Booleans and Truthiness
A boolean is true or false. Every value is also either truthy or falsy when used in a condition. The falsy values are false, 0, "" (empty string), null, undefined and NaN. Everything else is truthy, including "0" and empty arrays.
Use !! or Boolean() to see how a value is treated.
Example
console.log(Boolean(0), Boolean(""), Boolean(null));
console.log(Boolean("0"), Boolean([]), Boolean({}));
const name = "";
if (!name) {
console.log("Please enter a name");
}Exercise
Turn the value into a boolean.
const ok = ("hi");
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.