<body>
<h4>#1: A number divided by a non-numeric string becomes NaN (Not a Number):</h4>
<p id="demo1"></p>
<hr />
<h4>#2: A number divided by a numeric string becomes a number:</h4>
<p id="demo2"></p>
<hr />
<h4>#3: Find out if a value is Not a Number with the isNaN() function::</h4>
<p id="demo3"></p>
<hr />
<h4>#4: If you use NaN in a mathematical operation, the result will also be NaN:</h4>
<p id="demo4"></p>
<hr />
<h4>#5: If you use NaN in a mathematical operation, the result can be a concatination:</h4>
<p id="demo5"></p>
<hr />
<h4>#6: The typeof NaN is:</h4>
<p id="demo6"></p>
<script>
// THIS IS #1
document.getElementById("demo1").innerHTML =
"100 / \"Apple\" = " + 100 / "Apple" + " (Not a Number)";
// THIS IS #2
document.getElementById("demo2").innerHTML =
"100 / \"10\" = " + 100 / "10";
// THIS IS #3
document.getElementById("demo3").innerHTML =
"isNaN(100 / \"Apple\") = " + isNaN(100 / "Apple") + " (see #1)";
// THIS IS #4
var x = NaN;
var y = 5;
var z = x + y;
document.getElementById("demo4").innerHTML =
" if x = NaN and y = 5 and x + y = z, then z = " + z +
<br /> ", therefore x + y = " + z;
// THIS IS #5
document.getElementById("demo5").innerHTML =
" x + y = " + x + y;
// THIS IS #6
document.getElementById("demo6").innerHTML =
typeof NaN;
</script>
</body>
|
#1: A number divided by a non-numeric string becomes NaN (Not a Number):
#2: A number divided by a numeric string becomes a number:
#3: Find out if a value is Not a Number with the isNaN() function::
#4: If you use NaN in a mathematical operation, the result will also be NaN:
#5: If you use NaN in a mathematical operation, the result can be a concatination:
#6: The typeof NaN is:
|