CodesJava

Easy learning with example program codes

JavaScript isNaN() function


The isNan() function returns true if the variable value is not a number otherwise return false. It internally checks whether the specified value is an illegal number or not.

Syntax:

isNaN(value)

Parameters:
value: It represents the value to be check for not a number.

Returns:
It returns true if the value is a illegal number otherwise return false.

Example:

<!DOCTYPE html>
<html>
<body>
 
<script>
function testNaN() {
  var result = "";
  result = result + isNaN(45) + ": 45<br>";
  result = result + isNaN(-5.2) + ": -5.2<br>";
  result = result + isNaN(25-12) + ": 5-2<br>";
  result = result + isNaN(0) + ": 0<br>";
  result = result + isNaN('23') + ": '123'<br>";
  result = result + isNaN('codesjava') + ": 'codesjava'<br>";
  result = result + isNaN('2019/05/12') + ": '2019/05/12'<br>";
  result = result + isNaN('') + ": ''<br>";
  result = result + isNaN(true) + ": true<br>";
  result = result + isNaN(undefined) + ": undefined<br>";
  result = result + isNaN('NaN') + ": 'NaN'<br>";
  result = result + isNaN(NaN) + ": NaN<br>";
  result = result + isNaN(0 / 0) + ": 0 / 0<br>";
 
  document.write(result);
}
testNaN();
</script>
 
</body>
</html>

Output:

false: 45
false: -5.2
false: 5-2
false: 0
false: '123'
true: 'codesjava'
true: '2019/05/12'
false: ''
false: true
true: undefined
true: 'NaN'
true: NaN
true: 0 / 0

Related topics:

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki