undefined 的布尔值是 false
- <!DOCTYPE html>
- <html>
- <body>
- <p>显示 undefined 的布尔值:</p>
- <button onclick="myFunction()">试一试</button>
- <p id="demo"></p>
- <script>
- function myFunction() {
- var x;
- document.getElementById("demo").innerHTML = Boolean(x);
- }
- </script>
- </body>
- </html>