Global isNaN() Function - Javascript Global

Javascript examples for Global:isNaN

Description

The isNaN() function returns true if the value equates to NaN. Otherwise it returns false.

The global isNaN() function, converts the tested value to a Number, then tests it.

Number.isNaN() does not convert the values to a Number, and returns false it is not a Number.

Parameter Values

Parameter Description
value Required. The value to be tested

Return Value:

A Boolean. Returns true if the value is NaN, otherwise it returns false

The following code shows how to Check whether a value is NaN:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  w  w w.j a va 2 s  . c  o  m*/
    var res = "";
    res = res + isNaN(123) + ": 123<br>";
    res = res + isNaN(-1.23) + ": -1.23<br>";
    res = res + isNaN(4-2) + ": 4-2<br>";
    res = res + isNaN(0) + ": 0<br>";
    res = res + isNaN('123') + ": '123'<br>";
    res = res + isNaN('Hi') + ": 'Hi'<br>";
    res = res + isNaN('2020/12/12') + ": '2020/12/12'<br>";
    res = res + isNaN('') + ": ''<br>";
    res = res + isNaN(true) + ": true<br>";
    res = res + isNaN(undefined) + ": undefined<br>";
    res = res + isNaN('NaN') + ": 'NaN'<br>";
    res = res + isNaN(NaN) + ": NaN<br>";
    res = res + isNaN(0 / 0) + ": 0 / 0<br>";

    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials