Blogger Ever

Detect NaN in Javascript

Non numeric values in a string returns NaN, you can detect them using a universal function instead of ordinary methods.
Detect NaN in Javascript

NaN is returned when a text field value in not a number. But to detect it, you can't write an if condition that variable x is equals to NaN because NaN is not equal to itself, so what you going to use is a an universal function.

Javascript well, have a solution for everything and this one too. Javascript have an universal function that isNan() which returns the value in the form of boolean. You check weather the return value is true or false and add your condition according to that.

But yes with this universal function we are using if condition.
var x=document.getElementById('foo').value;
if(isNaN(x)==true){
// Do Something
}

Type number or string and see what you get.
Blogger

2013-2016 Copyright Blogger E\ver . Coded, managed and founded by Mohammad Hamza (@hamzadhamiya) . Hosted on Blogger and fonts used are Raleway and Open Sans.