JavaScript isNaN function

 The JavaScript isNaN function is used to determine whether the parameter is a special non-numeric value NaN. If it is, it will return true, and if it is not, it will return false. Note that the isNaN function will convert the parameter to a number. If the conversion is successful, it will True is returned, false is returned if it fails.


javascript isNaN syntax example

isNaN (parameter to be detected);


NaN in JavaScript is a special non-numeric value, so isNaN must be used to detect it. The parameter to be detected is a required item. If left blank, it will return true.

javascript isNaN implementation example
<script type='text/javascript'>
document.write( isNaN() +'<br>'); // Output true
document.write( isNaN("") +'<br>'); // Output false
document.write( isNaN(12345) +'<br>'); // Output false
document.write( isNaN("12345") +'<br>'); // Output false
document.write( isNaN("A12") +'<br>'); // Output true
document.write( isNaN( NaN ) +'<br>'); // Output true
document.write( isNaN( 0/0 ) +'<br>'); // Output true
document.write( isNaN( 'x' ) +'<br>'); // Output true
</script>
To learn more about JavaScript NaN properties, please refer to this article: Introduction to JavaScript NaN Properties .

Post a Comment

0 Comments