Sometimes when we are programming, we run into errors that we need to debug and fix. I will talk about debugging to a more in-depth level another time. In this post, I wnat to talk about NaN. Sometimes in programming, we receive an NaN error. So what does that mean?
NaN stands for Not a Number. Ok, so now we know what NaN stands for, but what does it mean. How is this error generated?
What it means is the program is telling you that it expected a number (data type) and it received something else. Let’s see an example…
[code lang=”js”]
var total = 12 * "text";
alert(total);
[/code]
As you can see, we are attempting to multiply the number 12 with the word ‘text’. This would result in NaN. It expected a number and it received a string.
Many times you utilize variables in your calculations and receive this error. While a tad more complex to debug, it is the same error. It means that one of the variables in the calculation is not a number.
Happy Coding!
Clay Hess
Webolution Designs