YouTip LogoYouTip

Jsref Isnan

# JavaScript isNaN() Function ## Definition and Usage The isNaN() function determines whether a value is NaN (Not-a-Number). In JavaScript, NaN is the only value that is not equal to itself. You can use this function to determine whether an arithmetic result is a legal number. --- ## Browser Support | Element | Chrome | IE | Firefox | Safari | Opera | |---------|--------|-----|---------|--------|-------| | isNaN() | Yes | Yes | Yes | Yes | Yes | --- ## Syntax ```javascript isNaN(value) ``` ## Parameters | Parameter | Description | |-----------|-------------| | value | Required. The value to be tested. | ## Return Value | Type | Description | |------|-------------| | Boolean | Returns true if the value is NaN, otherwise returns false. | ## Technical Details | Technical | Description | |-----------|-------------| | JavaScript Version: | 1.2 | --- ## More Examples ### Example 1 ```html

Please input a value:

function myFunction() { var x = document.getElementById("demo").value; if (isNaN(x)) { document.getElementById("pid").innerHTML = "Input is not a number"; } else { document.getElementById("pid").innerHTML = "Input is a number"; } } ``` ### Example 2 ```javascript document.write(isNaN(123) + "
"); document.write(isNaN(-1.23) + "
"); document.write(isNaN(5-2) + "
"); document.write(isNaN(0) + "
"); document.write(isNaN("Hello") + "
"); document.write(isNaN("2005/12/12") + "
"); ``` Output: ``` false false false false true true ``` --- ## Related Pages JavaScript Reference: ( ---
* ( * ( * (mailto:admin@) * (
← Jsref NumberJsref Isfinite β†’