isNaN()

Creator:
coolcoolcool
Description:
Teaches the basics of isNaN()

isNaN() is used to check if the value passed as the parameter is not a numeric value. NaN means not a number. So, isNan means is not a number.

An example where this could be used is in a page submission script. Here is a simple example of it being used in an if statement.

<script>
var let = "letters"; // this is not a number
//checks to see if it isn’t
if(isNaN(let)){
    alert("Please enter a number"); // if it isn’t it displays Please enter a number
} else {
    alert("You entered a number"); //if it is it displays You entered a number
}
</script>

In the first example this can be used to alert the user to hit back in there browser and enter a number if the code is changed to do so. You now know how to use isNaN. I hope you can find some uses for it.

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <b> <u> <i> <hr> <img src <url=
  • Lines and paragraphs break automatically.

More information about formatting options