如何检查类型是否为布尔值 [英] How to check if type is Boolean
本文介绍了如何检查类型是否为布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查变量的类型是否为布尔型?
How can I check if a variable's type is of type Boolean?
我的意思是,有一些替代方法,例如:
I mean, there are some alternatives such as:
if(jQuery.type(new Boolean()) === jQuery.type(variable))
//Do something..
但这对我来说似乎并不好.
But that doesn't seem pretty to me.
有没有更清洁的方法来实现这一目标?
Is there a cleaner way to achieve this?
推荐答案
这就是 typeof
在那里.括号是可选的,因为它是 operator .
if (typeof variable === "boolean"){
// variable is a boolean
}
这篇关于如何检查类型是否为布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文