close

How to check if type is Boolean

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to check if type is Boolean in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to check if type is BooleanHow to check if type is Boolean ?

  1. How to check if type is BooleanHow to check if type is Boolean ?

    check if type is BooleanHow to check if type is Boolean I would go with Lodash: isBoolean checks whether the passed-in variable is either primitive boolean or Boolean wrapper object and so accounts for all cases.

  2. check if type is BooleanHow to check if type is Boolean

    check if type is BooleanHow to check if type is Boolean I would go with Lodash: isBoolean checks whether the passed-in variable is either primitive boolean or Boolean wrapper object and so accounts for all cases.

Method 1

That’s what typeof is there for. The parentheses are optional since it is an operator.

if (typeof variable == "boolean") {
    // variable is a boolean
}

Method 2

I would go with Lodash: isBoolean checks whether the passed-in variable is either primitive boolean or Boolean wrapper object and so accounts for all cases.

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment