Jump to content

MichalB

Members
  • Posts

    1
  • Joined

  • Last visited

MichalB's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I would like to suggest to change the example in the JavaScript isNaN() Function topic (https://www.w3schools.com/jsref/jsref_isnan.asp) to the one below. I have added parseFloat of every test example. It shows that sometimes isNaN returns false, but parseFloat returns NaN. Interesting might be also treatment of the date. <!DOCTYPE html> <html> <body> <p>The isNaN() function returns true if the value is NaN (Not-a-Number), and false if not.</p> <p>Click the button to check whether a number is an illegal number.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var res = ""; res = res + isNaN(123) + ": 123 -> " + parseFloat(123) + "<br>"; res = res + isNaN(-1.23) + ": -1.23 -> " + parseFloat(-1.23) + "<br>"; res = res + isNaN(5-2) + ": 5-2 -> " + parseFloat(5-2) + "<br>"; res = res + isNaN(0) + ": 0 -> " + parseFloat(0) + "<br>"; res = res + isNaN('123') + ": '123' -> " + parseFloat('123') + "<br>"; res = res + isNaN('Hello') + ": 'Hello' -> " + parseFloat('Hello') + "<br>"; res = res + isNaN('2005/12/12') + ": '2005/12/12' -> " + parseFloat('2005/12/12') + "<br>"; res = res + isNaN('') + ": '' -> " + parseFloat('') + "<br>"; res = res + isNaN(true) + ": true -> " + parseFloat(true) + "<br>"; res = res + isNaN(undefined) + ": undefined -> " + parseFloat(undefined) + "<br>"; res = res + isNaN(null) + ": null -> " + parseFloat(null) + "<br>"; res = res + isNaN('NaN') + ": 'NaN' -> " + parseFloat('NaN') + "<br>"; res = res + isNaN(NaN) + ": NaN -> " + parseFloat(NaN) + "<br>"; res = res + isNaN(0 / 0) + ": 0 / 0 -> " + parseFloat(0 / 0) + "<br>"; document.getElementById("demo").innerHTML = res; } </script> </body> </html>
×
×
  • Create New...