Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Number.isNaN() Method

  • Last Updated : 04 Sep, 2020

Below is the example of the Number.isNaN() Method.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

  • Example:




    <script>
    function GFGFun() {
      var res = "";
      res = res + Number.isNaN(123);
    document.write(res);  
      
    }
    GFGFun();
    </script>
  • Output:
    false

The Number.isNan method in JavaScript is used to determines whether the passed value is NaN(Not a Number) and is of the type “Number”.
In JavaScript, the value NaN is considered a type of number.

Syntax:

Number.isNaN(value)

Parameters Used:
1. Value :It is the value which is to be tested for NaN.



Return Value:
The Number.isNaN() method in JavaScript returns true if the passed value is Nan and is of the type number,else it returns false.

Examples:

Input : 0/0
Output : true
     
Input : 213
Output : false

Input : '213'
Output : false

Input : 'hello'
Output : false

Input : NaN
Output : true

  1. When an equation resulting in infinite value is passed as a parameter.




    <script>
    function GFGFun() {
      var res = "";
      res = res + Number.isNaN(0/0);
    document.write(res);  
      
    }
    GFGFun();
    </script>

    Output:

    Output : true
  2. When a number is passed as a parameter.




    <script>
    function GFGFun() {
      var res = "";
      res = res + Number.isNaN(321);
    document.write(res);  
      
    }
    GFGFun();
    </script>

    Output:

    Output : false
  3. When a number in string representation is passed as a parameter.




    <script>
    function GFGFun() {
      var res = "";
      res = res + Number.isNaN(213);
    document.write(res);  
      
    }
    GFGFun();
    </script>

    Output:

    Output : false
  4. When a string is passed as a parameter.




    <script>
    function GFGFun() {
      var res = "";
      res = res + Number.isNaN("hello");
    document.write(res);  
      
    }
    GFGFun();
    </script>

    Output:

    Output : false
  5. When Nan is passed as a parameter.




    <script>
    function GFGFun() {
      var res = "";
      res = res + Number.isNaN(NaN);
    document.write(res);  
      
    }
    GFGFun();
    </script>

    Output:

    Output : true

Supported Browsers:

  • Google Chrome
  • Internet Explorer 12
  • Firefox 32
  • Apple Safari 9
  • Opera 22



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!