Boolean Conversion

Converting values to boolean.

Examples

Using Boolean()

Explicit conversion function.

console.log(Boolean("Hello")); // true
console.log(Boolean("")); // false

Using !! (Double NOT)

Shorthand conversion.

let x = "Hello";
console.log(!!x); // true
let y = 0;
console.log(!!y); // false

User Input Check

Common pattern to check for empty input.

let input = "";
if (!input) {
  alert("Please enter a value");
}

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.