The isNaN() function determines whether a value is NaN (Not-A-Number) or not. Note that parseInt approach may not work with strings having valid number prefix. Alternatively we can also use Number() function.
Example – isNaN returning false
<script> document.write(isNaN("37") + "<br>"); document.write(isNaN("37.37") + "<br>"); document.write(isNaN("") + "<br>"); document.write(isNaN(" ") + "<br>"); document.write(isNaN(null) + "<br>"); document.write(isNaN(true) + "<br>"); document.write(isNaN(false) + "<br>"); </script>
Example – isNaN returning true
<script> document.write(isNaN("123ABC") + "<br>"); document.write(isNaN(NaN) + "<br>"); document.write(isNaN(undefind) + "<br>"); document.write(isNaN({}) + "<br>"); </script>