Underscore.js | _.isFinite() with Examples

_.isFinite() function:

  • It is used to check whether the value of the parameter passed is finite or not.
  • If the parameter has infinite value the the output is false otherwise, true.
  • We can even perform any operation like addition, subtraction in this function.

Syntax:

_.isFinite(object)

Parameters:
It takes only one argument which is the argument that needs to be checked.



Return value:
It returns true if the parameter has a finite value otherwise it returns false.

Examples:

  1. Passing a positive number to the _.isFinite() function:
    The _.isFinite() function takes the number that is passed to it. Since every number have a finite value, therfore when it will check it will declare it’s parameter passed as a finite variable. And hence the output will be false.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <html>
        
    <head>
        <script src
        </script>
    </head>
        
    <body>
        <script type="text/javascript">
            console.log(_.isFinite(10));
        </script>
    </body>
        
    </html>

    chevron_right

    
    

    Output:

  2. Passing a negative number to the _.isFinite() function:
    The _.isFinite() function takes the number that is passed to it. Since, it is a negative number but still have a value so, for the same reason as above the _.isFinite() function will declare it’s parameter passed as a finite variable. And hence the output will be false.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <html>
        
    <head>
        <script src
        </script>
    </head>
        
    <body>
        <script type="text/javascript">
            console.log(_.isFinite(-10));
        </script>
    </body>
        
    </html>

    chevron_right

    
    

    Output:

  3. Passing a defined variable to the _.isFinite() function:
    The _.isFinite() function takes the parameter passed to it which is variable ‘a’ here. Then it checks the value of ‘a’ which is 10. It is not finite. Therefore, the answer is false.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <html>
        
    <head>
        <script src
        </script>
    </head>
        
    <body>
        <script type="text/javascript">
            var a=1000;
            console.log(_.isFinite(a));
        </script>
    </body>
        
    </html>

    chevron_right

    
    

    Output:

  4. Passing a variable without initializing to the _.isFinite() function:
    The _.isFinite() function takes the parameter passed to it which is variable ‘a’ here. Then it checks the value of ‘a’ which is not defined and hence is not fixed. It means ‘a’ has infinite values. Therefore, the answer is true.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!-- Write HTML code here -->
    <html>
        
    <head>
        <script src
       </script>
    </head>
        
    <body>
        <script type="text/javascript">
            var a;
            console.log(_.isFinite(a));
        </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

<!-- Write HTML code here -->
<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.