How to check if type is Boolean

前端 未结 16 1739
深忆病人
深忆病人 2020-12-07 10:09

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(         


        
16条回答
  •  太阳男子
    2020-12-07 10:45

    Sometimes we need a single way to check it. typeof not working for date etc. So I made it easy by

    Date.prototype.getType() { return "date"; }
    

    Also for Number, String, Boolean etc. we often need to check the type in a single way...

提交回复
热议问题