Related Articles

Related Articles

JavaScript Number.isNaN() Method
  • Last Updated : 04 Sep, 2020

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

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

  • 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.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    Output : true

Supported Browsers:

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

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :