源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>不要创建一个布尔对象.</p> <p>布尔值和对象不能被安全的比较.</p> <p id="demo"></p> <script> var x = false; // x is a boolean var y = new Boolean(false); // y is an object document.getElementById("demo").innerHTML = typeof x + "<br>" + typeof y; </script> </body> </html>
运行结果