其它数据类型转 boolean

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了其它数据类型转 boolean相关的知识,希望对你有一定的参考价值。

大体分两种:隐式类型转换和显式类型转换

隐式类型转换用 !!

 var str = "abc";
 str = !!str;
 console.log(typeof str);  //boolean

 

显式类型转换用Boolean()

var str = "abc";
str = Boolean(str);
console.log(typeof str); //boolean

 

以上是关于其它数据类型转 boolean的主要内容,如果未能解决你的问题,请参考以下文章