javascript中的数据类型boolean

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6         <script type="text/javascript">
 7             
 8             /*
 9              * 将其他的数据类型转换为Boolean
10              *     - 使用Boolean()函数
11              *         - 数字 ---> 布尔
12              *             - 除了0和NaN,其余的都是true
13              * 
14              *         - 字符串 ---> 布尔
15              *             - 除了空串,其余的都是true
16              * 
17              *         - null和undefined都会转换为false
18              * 
19              *         - 对象也会转换为true
20              *         
21              */
22             
23             var a = 123; //true
24             a = -123; //true
25             a = 0; //false
26             a = Infinity; //true
27             a = NaN; //false
28             
29             //调用Boolean()函数来将a转换为布尔值
30             a = Boolean(a);
31             
32             a = " ";
33             
34             a = Boolean(a);
35             
36             a = null; //false
37             a = Boolean(a);
38             
39             a = undefined; //false
40             a = Boolean(a);
41             
42             console.log(typeof a);
43             console.log(a);
44             
45         </script>
46     </head>
47     <body>
48     </body>
49 </html>
原文地址:https://www.cnblogs.com/lvjianqun/p/10300699.html