From my experience I know, that I can get NaN
when doing some division or when trying to make a number out of string, when it actually does not contain a number. Are there any other situations, when I can get a NaN
. In particular -- is it possible to get it from multiplication?
This is a piece of code, that I use in my PhoneGap application:
var g = 9.80665;
acceleration.x = (acceleration.x * g).toFixed(2);
acceleration.y = (acceleration.y * g).toFixed(2);
acceleration.z = ((acceleration.z + 1) * g).toFixed(2);
An acceleration
is a base PhoneGap object and I can hardly believe, that it contains a string or any other value, except float, that could result in a NaN
.
However, in some certain situations (on some specific devices) I'm getting a NaN
out of above.
It isn't a problem for me to "secure" above values with a code like this:
acceleration.x = (parseFloat(acceleration.x) || 0) + ' m/s\u00b2';
acceleration.y = (parseFloat(acceleration.y) || 0) + ' m/s\u00b2';
acceleration.z = (parseFloat(acceleration.z) || 0) + ' m/s\u00b2';
But, I'm really curious, when and why I can get a NaN
after doing just a multiply of some values?
BTW: I've read this at MDN, as good as many related answers here at Stack Overflow, but to brought me no help or answer to my question.