DEV Community

bomoniyi
bomoniyi

Posted on

Examples of Falsy Values in JS

// What will the following console logs display? (they're all true and false)

// console.log("Challenge 1:")

// console.log(!undefined); // true
// console.log(Boolean(NaN)); // false
// console.log(false === false); // true
// console.log(5 === "5"); //false(comparing number to string)
// console.log("Hello" == "hello");//false(loose comp. one has caps)

console.log("Challenge 2:")

console.log(Boolean(0)); // false
console.log(Boolean("0")); // true (string)
console.log(Boolean("")); // false
console.log(!null); // true
console.log(!!"hello"); // true (you're flipping the string around twice - true-> false -> true)

Top comments (0)