Tutorialspoint.dev

Number.isNaN() In JavaScript

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 type="text/javascript">
        var num=0/0;
             document.write("Output : " + num.isNaN());          
          </script>

    Output:

    Output : true
  2. When a number is passed as a parameter.
    <script type="text/javascript">
        var num=213;
             document.write("Output : " + num.isNaN());          
          </script>

    Output:

    Output : false
  3. When a number in string representation is passed as a parameter.
    <script type="text/javascript">
        var test='213';
             document.write("Output : " + test.isNaN());          
          </script>

    Output:

    Output : false
  4. When a string is passed as a parameter.
    <script type="text/javascript">
        var test='hello';
             document.write("Output : " + test.isNaN());          
          </script>

    Output:

    Output : false
  5. When Nan is passed as a parameter.
    <script type="text/javascript">
        var check=Nan;
             document.write("Output : " + check.isNaN());          
          </script>

    Output:

    Output : true


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter