Underscore.js | _.isNaN() with Examples

_.isNaN() function:

  • It is used to find whether the value of the object passed is NaN or not.
  • If the object’s value is NaN then the output will be true otherwise, it will be false.
  • We can even perform addition, substration etc operations in this function.

Syntax:

_.isNaN(object)

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



Return value:
It returns true if the object’s value is NaN otherwise it returns false.

Examples:

  1. Passing a number to the _.isNan() function:
    The _.isNaN() function takes the element that is passed to it and checks whether it’s value is NaN or not. Since a number is passed and we know that number have their own value so, 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">
            var a=10;
            console.log(_.isNaN(10));
        </script>
    </body>
       
    </html>

    chevron_right

    
    

    Output:

  2. Passing ‘NaN’ to the _.isNan() function:
    Since this time, Nan itself is passed to the function, so, when the function checks then the it finds that the variable passed has NaN value. Ans therefore, the output will be 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">
            console.log(_.isNaN(NaN));
        </script>
    </body>
        
    </html>

    chevron_right

    
    

    Output:

  3. Passing “undefined” to _.isNaN() function:
    The _.isNaN() function takes the parameter which here is “undefined” and starts checking. We know that, “Undefined” does not have any value and hence it’s value is defintely not NaN. 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">
            console.log(_.isNaN(undefined));
        </script>
    </body>
        
    </html>

    chevron_right

    
    

    Output:

  4. Performing operations on the output of _.isNan() function:
    Here, we are using the example 2 and 3 explained above. And then storing their value in variables ‘a’ and ‘b’. Therefore, the variable ‘a’ has false and ‘b’ has true. Finally we are performing an OR operation on both the ‘a’ and ‘b’ and storing the result in variable ‘c’. Since ‘b’ is true, therefore, ‘c’ is 1.
    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 = _.isNaN(undefined);
            var b = _.isNaN(NaN);
            var c = a + b;
            console.log(a);
            console.log(b);
            console.log(c);
        </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.