revision:
The Number.isNaN() static method determines whether the passed value is the number value NaN, and returns false if the input is not of the Number type. It is a more robust version of the original, global isNaN() function.
Number.isNaN(value)
Parameters:
value : required. The value to be tested for NaN.
function typeOfNaN(x) { if (Number.isNaN(x)) { return 'Number NaN'; } if (isNaN(x)) { return 'NaN'; } } console.log(typeOfNaN('100F')); // Expected output: "NaN" console.log(typeOfNaN(NaN)); // Expected output: "Number NaN"
<div> <p id="NaN-1"></p> <p id="NaN-2"></p> <p id="NaN-3"></p> <p id="NaN-4"></p> </div> <script> document.getElementById("NaN-1").innerHTML = " Number.isNaN(NaN) : " + Number.isNaN(NaN); // true document.getElementById("NaN-2").innerHTML = " Number.isNaN(Number.NaN) : " + Number.isNaN(Number.NaN); // true document.getElementById("NaN-3").innerHTML = " Number.isNaN(0 / 0) : " + Number.isNaN(0 / 0); // true document.getElementById("NaN-4").innerHTML = " Number.isNaN(37) : " + Number.isNaN(37); // false </script>
<div> <p id="NaN-5"></p> </div> <script> let result = "Is 123 NaN? " + Number.isNaN(123) + "<br>" + "Is -123 NaN? " + Number.isNaN(-1.23) + "<br>" + "Is '123' NaN? " + Number.isNaN('123') + "<br>" + "Is 0/0 NaN? " + Number.isNaN(0 / 0); document.getElementById("NaN-5").innerHTML = result; </script>
<div> <p id="NaN-6"></p> </div> <script> let result1 = "Is 5-2 NaN? " + Number.isNaN(5-2) + "<br>" + "Is 0 NaN? " + Number.isNaN(0) + "<br>" + "Is 'Hello' NaN? " + Number.isNaN('Hello') + "<br>" + "Is '2005/12/12\ NaN? " + Number.isNaN('2005/12/12') + "<br>" + "Is ' ' NaN? " + Number.isNaN(''); document.getElementById("NaN-6").innerHTML = result1; </script>