空字符串的布尔值是 false

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>显示 "" 的布尔值:</p>
  6.  
  7. <button onclick="myFunction()">试一试</button>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. function myFunction() {
  13. var x = "";
  14. document.getElementById("demo").innerHTML = Boolean(x);
  15. }
  16. </script>
  17.  
  18. </body>
  19. </html>