拥有真正值的一切均为 true

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p id="demo"></p>
  6.  
  7. <script>
  8. var b1 = Boolean(100);
  9. var b2 = Boolean(3.14);
  10. var b3 = Boolean(-15);
  11. var b4 = Boolean("Hello");
  12. var b5 = Boolean('false');
  13. var b6 = Boolean(1 + 7 + 3.14);
  14.  
  15. document.getElementById("demo").innerHTML =
  16. "100 是 " + b1 + "<br>" +
  17. "3.14 是 " + b2 + "<br>" +
  18. "-15 是 " + b3 + "<br>" +
  19. "任何(非空)字符串是 " + b4 + "<br>" +
  20. "即使字符串 'false' 也是 " + b5 + "<br>" +
  21. "任何表达式(除了零)是 " + b6;
  22. </script>
  23.  
  24. </body>
  25. </html>