Basic JavaScript Question:

How to test for bad numbers using JavaScript?

Tweet Share WhatsApp

Answer:

The global method, "isNaN()" can tell us about value if a number has gone bad in JavaScript.

var temperature = parseFloat(myTemperatureWidget.value);

if(!isNaN(temperature)) {
alert("Please enter a valid temperature.");
}

Download JavaScript PDF Read All 114 JavaScript Questions
Previous QuestionNext Question
How to convert numbers to strings using JavaScript? What's Math Constants and Functions using JavaScript?