首页 > 试题广场 >

bod...

[单选题]
<html>
<body>
<script type="text/javascript">
var test=new Boolean();
document.write(test);
document.write("<br />");

var test=new Boolean(0);
document.write(test);
document.write("<br />");

var test=new Boolean(null);
document.write(test);
document.write("<br />");

var test=new Boolean("");
document.write(test);
document.write("<br />");

var test=new Boolean(NaN);
document.write(test);
document.write("<br />");
</script>

</body>
</html>
上述代码的输出结果为(      )
  • false false false false false
  • false true false false false
  • false false true test Boolean
  • 其他几项都不对
Boolean类型转换:
    1.对于String:只有非空字符串为真
    2.对于Number:除了0和NaN之外都为真
    3.对于Boolean:true为真
    4.对于Object:除了null之外都为真
    5.undefined为false;
发表于 2019-11-16 21:56:27 回复(4)
1) 当作为一个构造函数(带有运算符 new)调用时,Boolean() 将把它的参数转换成一个布尔值,并且返回一个包含该值的 Boolean 对象。 如果作为一个函数(不带有运算符 new)调用时,Boolean() 只将把它的参数转换成一个原始的布尔值,并且返回这个值。 2) 注释:如果省略 value 参数,或者设置为 0、-0、null、""、false、undefined 或 NaN,则该对象设置为 false。否则设置为 true(即使 value 参数是字符串 "false")。
发表于 2019-08-26 08:53:52 回复(1)
Boolean类型只有true 和 false
把其他类型转换为Boolean类型 只有五个值转换为false 其余都是true
0 NaN null undefined ""
发表于 2020-02-20 14:06:02 回复(0)
var a=new boolean();这个不好理解。可以类比成:var a; a=boolean(a);//boolean(undefined) false
发表于 2021-05-31 15:00:14 回复(0)
js默认布尔值为false,而且空串,0,null,undefined,nan也为false
发表于 2019-10-17 19:43:02 回复(0)
Boolean类型转换:1.对于String:只有非空字符串为真; 2.对于Number:除了0和NaN之外都为真3.对于Boolean:true为真;4.对于Object:除了null之外都为真; 5.undefined为false;
发表于 2021-06-06 16:48:46 回复(0)
发表于 2021-04-22 15:27:33 回复(0)
            console.log(new Boolean());//PrimitiveValue原始值为false
            console.log(new Number());//PrimitiveValue原始值为0
            console.log(new String());//PrimitiveValue原始值为""空字符串
            console.log(new function(){});//PrimitiveValue原始值为{}
发表于 2019-11-16 15:40:25 回复(0)

使用Boolean(value)方法可以强制转换任意值为boolean类型,除了以下六个值,其他都是自动转为true:

发表于 2020-09-18 21:06:13 回复(1)
使用场景 const array = [3, 0, 6, 7, '', false]; array.filter(Boolean); // 输出 (3) [3, 6, 7]
发表于 2022-09-03 22:43:41 回复(0)
Boolean类型转换:

    1.对于String:只有非空字符串为真

    2.对于Number:除了0和NaN之外都为真

    3.对于Boolean:true为真

    4.对于Object:除了null之外都为真

    5.undefined为false;

编辑于 2024-02-21 16:02:08 回复(0)
为啥变量没有提升,提升的话不就只有一个值吗

发表于 2022-04-13 15:41:36 回复(1)
Boolean类型转换:     1.对于String:只有非空字符串为真     2.对于Number:除了0和NaN之外都为真     3.对于Boolean:true为真     4.对于Object:除了null之外都为真     5.undefined为false;
发表于 2020-11-18 23:26:36 回复(0)
只有0,-0,undefind,null,“”,NaN,false,为false
发表于 2020-07-29 12:04:04 回复(0)