尚硅谷 Javascript 中其他数据类型转换为boolean值

/*
* 将其他的类型转换成Boolean
* - 使用Boolean()函数来将a转换为布尔值
* -数字—》布尔
* -除了0和NaN转换为布尔值为false 其他的都是true
*
* -字符串—》布尔
* - 除了空串,其余的都是true
* -null和undefined 都是false
*/
var a = 123;//true
a= -123;//true
a= 0;//false
a= Infinity;//true
a = NaN;//false
a = Boolean(a);
console.log(a);

		b= "hello";
		b =Boolean(b);
		console.log(typeof b);
		console.log(b);
		
		c = null
		c = Boolean(c);
		console.log(typeof c);
		console.log(c);
		
		d = null
		d = Boolean(d);
		console.log(typeof d);
		console.log(d);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值