js的显性转化Boolean()

xiaoxiao2021-02-28  3

js的显性转化Boolean()

该方法将值转化为布尔类值

var a = Boolean(123) typeof( a ) //a = true,a为Boolean类型 var a = Boolean("abc") typeof( a ) // a = true,a为boolean类型 var a = Boolean( 0 ) typeof( a ); //a = false,a为boolean类型 var a = Boolean(" 0 ") typeof( a ) //a = true,a为boolean类型

var a = Boolean(undefined); console.log( a ); //控制台打印false, a = false,a为Booolean类型

var a = Boolean( null ) console.log( a ) //控制台打印false, a = false;a为Booleanl类型 var b = Boolean(document); console.log( b ); //控制台打印true,b = true

var b = Boolean(Object); console.log( b ); //控制台打印true,b = true,b为boolean类型 var b = Boolean(window); console.log( b ); //控制台打印出true,b = true,b为布尔类型 当转化值为null,undefined,数值0时,会将其转化为false
转载请注明原文地址: https://www.6miu.com/read-2400202.html

最新回复(0)