Underscore.js | _isBoolean()

The Underscore.js is a JavaScript library that provides a lot of useful functions like the map, filter, invoke etc even without using any built-in objects.

The _isBoolean function is used to find whether the element passed is true/ false or something else. Boolean is a subset of algebra that is used to create true/false statements.
If the element has value either true or false then the output will be true otherwise it’s output will be false.
It is used when we have to distinguish between the elements which have true or false values and the other elements which do not have true/false as their values.

Syntax:

_.isBoolean(object)

Parameters:
It takes only one argument which is the object whose value needs to be checked.

Return value: It returns true when the object’s value is true or false otherwise it returns false.

  1. Passing a variable having number value to the _.isBoolean() function:
    The _.isBoolean() function takes the argument passed and then checks it’s value. It checks the argument’s value by comparing the value with both ‘true’ and ‘false’. If it is matched by any one of these, then output is true otherwise the output is false.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <html>
      
    <head>
        <script src=
      </script>
    </head>
      
    <body>
        <script type="text/javascript">
            var a = 10;
            console.log(_.isBoolean(a));
        </script>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

  2. Passing a variable having ‘false’ as it’s value to the _.isBoolean() function:
    If we pass an element that has ‘false’ assigned to it then also the same procedure as the previous will be followed. The argument’s value will be compared to both ‘true’ and ‘false’. Since it’s value is false, so it will be matched and hence the output will be true.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <html>
      
    <head>
        <script src=
      </script>
    </head>
      
    <body>
        <script type="text/javascript">
            var a = false;
            console.log(_.isBoolean(a));
        </script>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

  3. Passing ‘true’ to _.isBoolean() function:
    The _.Boolean() function, in this case, does not need to check the variable’s value as no variable is passed as an argument rather the value itself is passed. The value will be matched directly to ‘true’ and ‘false’. Since the passed argument is ‘true’ so it will be matched and hence the output will be true.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <html>
      
    <head>
        <script src=
      </script>
    </head>
      
    <body>
        <script type="text/javascript">
            console.log(_.isBoolean(true));
        </script>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

  4. Passing ‘null’ to the _.isBoolean() function:
    When we pass null value to the _.isBoolean() function then no error is generated rather the same checking procedure will be followed. Since after matching the null value to both the true and false, it will not be matched, so, the output will be false.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <html>
      
    <head>
        <script src=
      </script>
    </head>
      
    <body>
        <script type="text/javascript">
            console.log(_.isBoolean(null));
        </script>
    </body>
      
    </html>

    chevron_right

    
    

    Output:

NOTE:
These commands will not work in Google console or in firefox as for these additional files need to be added which they didn’t have added.
So, add the given links to your HTML file and then run them.
The links are as follows:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script type=
"text/javascript" src =
</script>

chevron_right




My Personal Notes arrow_drop_up

I like to do coding in C++C and java programming languages HTML and CSS always intersts me Sharing knowleged is the best way according to me to increase ones knwoledge

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.