728x90
SMALL
#JavaScript
#isNaN()
isNaN()
isNaN() - A function that checks if the parameter is a number (NaN is Not a Number).
Grammar
isNaN( value )
- value: Enter the value to check.
- Returns true if the parameter is not a number, false if it is a number.
example
- Returns false because 123.123 is a number.
- '123.123' is quoted but treated as a number and returns false.
- 'Not a Number' returns true because it is not a number.
- Returns false because 123*123 is a number.
- '123*123' has characters inside the quotes, so it treats it as not a number and returns true.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript</title>
<style>
body {
font-family: Consolas, monospace;
font-size: 16px;
line-height: 1.6;
}
</style>
</head>
<body>
<script>
var a = 123.123;
var b = '123.123';
var c = 'Not a Number';
var d = 123 * 123;
var e = '123 * 123';
document.write( '<p>123.123 : ' + isNaN( a ) + '</p>' );
document.write( '<p>\'123.123\' : ' + isNaN( b ) + '</p>' );
document.write( '<p>\'Not a Number\' : ' + isNaN( c ) + '</p>' );
document.write( '<p>123*123 : ' + isNaN( d ) + '</p>' );
document.write( '<p>\'123*123\' : ' + isNaN( e ) + '</p>' );
</script>
</body>
</html>
728x90
LIST