Introduction to JavaScript NaN property
JavaScript NaN is a special non-numeric value. To put it plainly, it is "not a representative of a number", NaN = Not a Number. So NaN is used to do mathematical operations in JavaScript or to do calculations with other numbers, and you will get NaN. In other words, NaN is not equal to any number (Number), nor is it equal to itself. It sounds a bit abstract. How to judge a parameter Is it NaN? It can be detected through the JavaScript isNaN function .
JavaScript NaN case study
var StrA="100";
var StrB="這是字串";
document.write(Number(StrA)+ "<br>"); // Output 100
document.write(isNaN(StrA)+ "<p>"); // Output false
document.write(Number(StrB)+ "<br>"); // Output NaN
document.write(isNaN(StrB)+ "<p>"); // Output true
</script>
Post a Comment
0 Comments