Home
<!DOCTYPE html> <html> <body> <h1>Demo: JavaScript Boolean</h1> <p id="p1">Boolean('Hello') returns </p> <p id="p2">Boolean('h') returns </p> <p id="p3">Boolean('10') returns </p> <p id="p4">Boolean([]) returns </p> <p id="p5">Boolean(a + b) returns </p> <script> var a = 10, b = 20; var b1 = Boolean('Hello'); // true var b2 = Boolean('h'); // true var b3 = Boolean(10); // true var b4 = Boolean([]); // true var b5 = Boolean(a + b); // true document.getElementById("p1").textContent += b1; document.getElementById("p2").textContent += b2; document.getElementById("p3").textContent += b3; document.getElementById("p4").textContent += b4; document.getElementById("p5").textContent += b5; </script> </body> </html>
Result: