NaN小结


The value NaN has a couple of unique properties. First, any operation involving NaN always returns NaN
(for instance, NaN /10), which can be problematic in the case of multistep computations. Second, NaN is
not equal to any value, including NaN . For example, the following returns false :
alert(NaN == NaN); //false
For this reason, ECMAScript provides the isNaN() function. This function accepts a single argument,
which can be of any data type, to determine if the value is “ not a number. ” When a value is passed
into isNaN() , an attempt is made to convert it into a number. Some non - number values convert into
numbers directly, such as the string “10” or a Boolean value. Any value that cannot be converted
into a number causes the function to return true . Consider the following:
alert(isNaN(NaN)); //true
alert(isNaN(10)); //false - 10 is a number
alert(isNaN(“10”)); //false - can be converted to number 10
alert(isNaN(“blue”)); //true - cannot be converted to a number
alert(isNaN(true)); //false - can be converted to number 1

你可能感兴趣的:(小结)